Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid erasing type objects when checking runtime cover #19320

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 5 commits into from
Jun 22, 2025

Conversation

hauntsaninja
Copy link
Collaborator

In particular, avoid erasing CallableType that represent type objects

Helps with #19159

In particular, avoid erasing CallableType that represent type objects

Helps with python#19159
@hauntsaninja hauntsaninja changed the title Only erase instances when checking runtime cover Avoid erasing type objects when checking runtime cover Jun 20, 2025

This comment has been minimized.

mypy/subtypes.py Outdated
@@ -2106,7 +2106,8 @@ def covers_at_runtime(item: Type, supertype: Type) -> bool:
supertype = get_proper_type(supertype)

# Since runtime type checks will ignore type arguments, erase the types.
supertype = erase_type(supertype)
if not isinstance(supertype, CallableType):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we only skip erase if the callable type represents a type object? What about overloaded callable types?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure how we would get here with other CallableType's (and we don't anywhere in the test suite). isinstance(item, CallableType) isn't really a thing that can happen at runtime.

I went ahead and restricted it to just type objects though!

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit 24b831a into python:master Jun 22, 2025
19 checks passed
@hauntsaninja hauntsaninja deleted the coveruntime branch June 22, 2025 06:23
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