-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Classmethod constructor pattern on a generic container with a bound typevar has incompatible type with fixed output type #18244
Comments
Hey @pechersky I can work on this issue.. please assign me with this. |
@kanishka-coder0809 we don't generally assign issues, but if you have a solution or ideas, please mention them here. You'll have to investigate further what is going on in the code sample and how mypy understands the code. @pechersky provided a detailed report already. |
This is expected. It might be clearer why this isn't valid if you consider what happens when you subclass class Foo(Container[Y]):
f = Foo.create_x_var(X()) # f is a `Foo` at runtime
reveal_type(f) # Revealed type is "__main__.Container[__main__.X]"
# uh oh! Runtime type and static type are incompatible. There are a few ways you can make something like this type safe:
|
Bug Report
Using a constructor pattern with
cls
instead of the explicit class term in a generic context gives a type error.To Reproduce
Expected Behavior
The
cls
call is accepted as well.Actual Behavior
Your Environment
mypy.ini
(and other config files): n/aThe text was updated successfully, but these errors were encountered: