-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add --allow-untyped-globals
flag that avoids partial type errors
#5670
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
Conversation
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.
7c23ac4
to
c352f83
Compare
reveal_type(x) # E: Revealed type is 'builtins.list[Any]' | ||
reveal_type(y) # E: Revealed type is 'builtins.dict[Any, Any]' | ||
|
||
[builtins fixtures/dict.pyi] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why this doesn't pass:
class C:
a = [] # Error here
def f(self) -> None:
reveal_type(self.a)
This still gives an error "Need type annotation for 'a'" on line 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because member checking has a totally different partial type path apparently, which I'm now going to merge.
Just a few thoughts about how we're categorizing this flag:
|
Re categorization: |
I still think it belongs better in strictness_group. This looks as follows currently:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
--permissive-toplevel
flag that avoids partial type errors --allow-untyped-globals
flag that avoids partial type errors
(Note that the flag ended up being renamed to |
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.
I don't love the flag name and would be happy to change it. This just adds an individual flag. Grouping into a
--strictness=0
configuration or something we should spin off as another bug, I think.