Skip to content

Improve warnings.catch_warnings #8229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2022
Merged

Conversation

AlexWaygood
Copy link
Member

  • __new__ -> __init__. This kind of __init__ overloading wasn't possible when the current stubs were written (see discussion in Add warnings.catch_warning type hints with Literal. #3464).
  • Remove the fictitious classes _catch_warnings_without_records and _catch_warnings_with_records, which don't exist at rutnime. Make the class generic instead.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2022

Diff from mypy_primer, showing the effect of this PR on open source code:

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/recwarn.py:160: error: Missing type parameters for generic type "catch_warnings"  [type-arg]

@AlexWaygood
Copy link
Member Author

Diff from mypy_primer, showing the effect of this PR on open source code:

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/recwarn.py:160: error: Missing type parameters for generic type "catch_warnings"  [type-arg]

This is a custom subclass of warnings.catch_warnings: https://github.com/pytest-dev/pytest/blob/b08c1dcf0e421b408653d185574baec7855e2439/src/_pytest/recwarn.py#L160

A comment in the source code indicates that, as they are well aware, this subclass already violates LSP by returning self in their __enter__ method: https://github.com/pytest-dev/pytest/blob/b08c1dcf0e421b408653d185574baec7855e2439/src/_pytest/recwarn.py#L209-L211

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Much cleaner.

@srittau srittau merged commit 73974e9 into python:master Jul 4, 2022
@AlexWaygood AlexWaygood deleted the warnings branch July 4, 2022 15:06
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