-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
mypy incorrectly infers the type of a variable from different branches #4061
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
Different people have different opinions about what should be inferred for resource_class: Type[Resource]
if release is True:
resources_class = iocage.lib.Releases.ReleasesGenerator
else:
resources_class = iocage.lib.Jails.JailsGenerator |
This doesn't seem to work. |
What about this: resource_class: Union[Type[iocage.lib.Releases.ReleasesGenerator],
Type[iocage.lib.Jails.JailsGenerator]]
if release is True:
resources_class = iocage.lib.Releases.ReleasesGenerator
else:
resources_class = iocage.lib.Jails.JailsGenerator |
Strange, I just tried this code on master and it works perfectly: class A: ...
class B(A): ...
class C(A): ...
resource: Type[A]
if bool():
resource = B
else:
resource = C |
okay! updated to mypy! to i can no longer say if this was the cause of my error, or the fact that i wrote thank you all for you help and patience 💜💜💜 |
in the following code,
mypy will issue the error:
Also note that both,
JailsGenerator
andReleaseGenerator
inherit from the same common classResource
.The text was updated successfully, but these errors were encountered: