Skip to content

Fix type hints of assert functions#1271

Merged
kingbuzzman merged 2 commits intopytest-dev:mainfrom
mschoettle:patch-1
Feb 27, 2026
Merged

Fix type hints of assert functions#1271
kingbuzzman merged 2 commits intopytest-dev:mainfrom
mschoettle:patch-1

Conversation

@mschoettle
Copy link
Contributor

@mschoettle mschoettle commented Feb 26, 2026

Updated type hints in assert functions to use Iterable instead of Collection. And have assertRaisesMessage return something to use as a context manager.

This is in line with django-stubs: https://github.com/typeddjango/django-stubs/blob/master/django-stubs/test/testcases.pyi

Version 4.12.0 raises the following errors with mypy:

error: "assertRaisesMessage" does not return a value (it only ever returns None)  [func-returns-value]

error: Argument 2 to "assertQuerySetEqual" has incompatible type "QuerySet[Foo, Foo]"; expected "Collection[Any]"  [arg-type]
note: "QuerySet" is missing following "Collection" protocol member:
note:     __contains__

Updated type hints in assert functions to use Iterable instead of Collection.
And have assertRaisesMessage return something to use as a context manager.
Copy link
Member

@kingbuzzman kingbuzzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks like you got it from here 😉 ah, right you added it in your description, eek. As you can see, I read code first then descriptions... foot, meet mouth. 😇

@kingbuzzman
Copy link
Member

Seems low risk. Merging.

@kingbuzzman kingbuzzman enabled auto-merge (squash) February 26, 2026 22:51
@kingbuzzman kingbuzzman merged commit 3955b18 into pytest-dev:main Feb 27, 2026
24 checks passed
@mschoettle mschoettle deleted the patch-1 branch February 27, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants