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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

@@ -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
Contributor

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

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