-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Order-dependent errors in class variable type checks #6119
Comments
My guess is this is cause by problems with MRO calculation, so the upcoming semantic analyzer refactoring should fix this. As a workaround, you can always topologically sort your classes, since Python classes always form a DAG w.r.t. inheritance. (Also you don't need to use quotes and type comment syntax in stubs) |
Thanks for the suggestion! That does work around the issue just fine.
I think I could have guessed this for the quoted syntax, but for type comment syntax I assumed that this was Python version dependent. If not, it would be nice to have that noted in the stubs format documentation somewhere. Maybe it's there already and I just missed it. |
Shouldn't this issue be gone with python3.7's postponed evaluation of type annotations? |
The false-positive error is no longer reproducible on mypy 0.720+ |
Apologies for the apparently-convoluted test case. I've found it to be surprisingly fragile.
which, when type-checking the stubs themselves gives:
sample.pyi:16: error: Incompatible types in assignment (expression has type "Dialog", base class "Widget" defined the type as "InitiallyUnowned")
The error appears to be highly order- and hierarchy-dependent.
If
Dialog
is declared afterFontSelectionDialog
, the bug goes away.If
Dialog
subclassesBin
instead ofWindow
, the bug goes away.If
Window
subclassesWidget
instead ofBin
, the bug goes away.It's probably worth mentioning that these are auto-generated stubs for GTK+/GObject introspection classes, so just manually adjusting ordering, etc. isn't really a good solution.
No error.
Python 3.6.7, mypy 0.650
Yes.
No flags. This is just type-checking the stubs themselves.
The text was updated successfully, but these errors were encountered: