Skip to content

Check class references to catch non-existant classes in match cases - #20042

Merged
hauntsaninja merged 3 commits into
python:masterfrom
A5rocks:check-class-references
Oct 10, 2025
Merged

hauntsaninja merged 3 commits into
python:masterfrom
A5rocks:check-class-references

Conversation

@A5rocks

@A5rocks A5rocks commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator

Fixes #20018.

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, thanks!

@github-actions

This comment has been minimized.

@A5rocks

A5rocks commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator Author

For the primer, (since I was confused about this for test results) this happens because there's no type annotations in the function signature so everything becomes Any, leading to Too many positional patterns for class pattern. Maybe I should remove that error for Any?

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe see if using type_info_from_type helps

@A5rocks

A5rocks commented Oct 10, 2025

Copy link
Copy Markdown
Collaborator Author

The issue was moreso that we didn't get __match_args__ for AnyType... but now hopefully the behavior is nicer. (This is an improvement over before, too!)

@A5rocks A5rocks changed the title Check class references to catch non-existant classes Check class references to catch non-existant classes in match cases Oct 10, 2025
@github-actions

This comment has been minimized.

Comment thread mypy/checkpattern.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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

ibis (https://github.com/ibis-project/ibis)
- ibis/common/tests/test_grounds_py310.py:38: error: Too many positional patterns for class pattern  [misc]

@hauntsaninja
hauntsaninja merged commit e03d3c1 into python:master Oct 10, 2025
20 checks passed
@A5rocks
A5rocks deleted the check-class-references branch October 10, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative attr-defined in match case

3 participants