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
@brianhelba
Copy link

@kingbuzzman Could you generate a new patch release with this fix soon? This is otherwise blocking the upgrade to 4.12 for my projects.

@kingbuzzman
Copy link
Member

kingbuzzman commented Mar 5, 2026

@brianhelba unfortunately, i do not possess such powers. @bluetech is the only one that can do it , @pelme, and @adamchainz are the only ones that can do it.

@kingbuzzman
Copy link
Member

Hum, if you want a release, can you make another PR and change the changelog please. This would go a long way in getting the release ready. Thats on me, I should have asked for this in the first place.

mschoettle added a commit to mschoettle/pytest-django that referenced this pull request Mar 6, 2026
Add changelog entry for pytest-dev#1271 for next version
@mschoettle mschoettle mentioned this pull request Mar 6, 2026
@mschoettle
Copy link
Contributor Author

Hum, if you want a release, can you make another PR and change the changelog please. This would go a long way in getting the release ready. Thats on me, I should have asked for this in the first place.

See #1271. Although someone will have to update it once the release date is known

kingbuzzman pushed a commit that referenced this pull request Mar 9, 2026
* Add changelog entry

Add changelog entry for #1271 for next version

* Apply suggestion from @mschoettle

* Apply suggestion from @mschoettle
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.

3 participants