-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feature request: explicity metaclass().__getitem__ typing #6313
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
Comments
It is expected that it works in runtime context but doesn't work in type context, because anything that appears in type context should be known statically. Consider a simpler example: def f() -> Type[int]: ...
x = f()() # OK, inferred type for x is `int`
y: f() # Fails The error message however is confusing, but then this is essentially a duplicate of #4030 |
By the way, the workaround for your case is to use |
Sorry, can you expand the last comment? |
from typing import TYPE_CHECKING
if TYPE_CHECKING:
<definition of Gen that would satisfy mypy>
else:
<your definition that will be executed at runtime> |
If I understand the reason this can't happen correctly, wouldn't this be solved by a |
Mypy does well with metaclass
__getitem__
when the class is instatiated,but in case of indexing just the child class, it fails:
I think it would be very useful to check, especially in case of function annotations
The text was updated successfully, but these errors were encountered: