-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
More permissive behavior when overriding class variables #5639
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
For what it's worth, this was also one of the most common causes of errors when running mypy on our big unannotated codebase. |
This does seem like a common pattern. However, I don't think this flag should be on by default. I'd rather have people who are starting anew turn something on over subtly changing the behavior for existing mypy users (and losing type safety they think exists). |
This is a tricky issue. To make it easier to start using mypy, we could perhaps generalize the concept of strictness levels, which are presets for certain sets of options. We already have one,
We can introduce We can later add additional strictness levels, but the above three would probably be sufficient for now. |
I think this was already discussed before, but I would also disable |
A major cause of false positives when checking new codebases is unannotated top level containers and Nones. Add a flag that suppresses both the "needs type annotation" errors and the assigning of NoneTyp to variables at the "toplevel" (not when nested in functions). To avoid throwing away too much type information, we give more precise types in these situations than previously, filling in the arguments to the type with `Any`. Closes #5639.
A major cause of false positives when checking new codebases is unannotated top level containers and Nones. Add a flag that suppresses both the "needs type annotation" errors and the assigning of NoneTyp to variables at the "toplevel" (not when nested in functions). To avoid throwing away too much type information, we give more precise types in these situations than previously, filling in the arguments to the type with `Any`. Closes #5639.
…5670) A major cause of false positives when checking new codebases is unannotated top level containers and Nones. Add a flag that suppresses both the "needs type annotation" errors and the assigning of NoneTyp to variables at the "toplevel" (not when nested in functions). To avoid throwing away too much type information, we give more precise types in these situations than previously, filling in the arguments to the type with `Any`. Closes #5639.
The following code fails to typecheck:
with
test.py:5: error: Incompatible types in assignment (expression has type "str", base class "A" defined the type as "None")
My proposal for fixing this is to add a new flag, on by default, that will cause class variables with the type
None
to instead be given the typeOptional[Any]
.Not sure what the flag should be called, though.
(I'm investigating top causes of errors when running mypy on an unannotated code base and this issue caused 60% of the 600+ errors generated when checking django.)
The text was updated successfully, but these errors were encountered: