You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add flag prohibiting annotation by Any resulting from an unanalyzed module #3205
I would expect this to be an error: if mypy doesn't know what MyType is, it shouldn't be a valid type. Instead, it assumes it's Any which is way more permissive behavior than I expect.
This is intentional. Everything non-annotated/unknown should have type Any by default. This is one of the key ideas of gradual typing, otherwise annotating a large codebase would be a non-starter.
For more control on mypy behaviour, you could use flags, for example:
so I understand that it is expected for unchecked imports to be Any - but what I did not expect is that we could use one of them as a type without any warning. It doesn't sound like any of those flags you are suggesting will fix this? Can we please reopen? (It doesn't look like I have the ability to do this myself)
anyhow I filed this task at the suggestion of @ddfisher, who thought a flag for a warning about this could be valuable
but what I did not expect is that we could use one of them as a type without any warning. It doesn't sound like any of those flags you are suggesting will fix this?
Yes, this case is not covered by current flags. And it looks like such flag is not too difficult to implement.
changed the title [-]using a type from an unanalyzed file to be a mypy error[/-][+]Add flag prohibiting annotation by Any resulting from an unanalyzed module[/+]on Apr 20, 2017
As some additional background, this happens when the --follow-imports=skip and --ignore-missing-imports flags are set.
To implement this, I'd start by adding an additional member to the AnyType class which tracks whether or not it's from a silent import. I'd then grep for ignore_missing_imports and follow_imports to find where ignored module imports are turned into Anys, and set the member I'd added to AnyType there.
Next, I'd add the new --disallow-implicit-any-types flag. It needs to be added to process_options in main.py and to Options in options.py. It should be a per-module option.
For the warning itself, I'd add checks to visit_func_def, visit_overloaded_func_def and visit_class_def in checker.py.
Finally, I'd add several tests for this functionality to the end of check-flags.test.
Activity
ilevkivskyi commentedon Apr 20, 2017
This is intentional. Everything non-annotated/unknown should have type
Anyby default. This is one of the key ideas of gradual typing, otherwise annotating a large codebase would be a non-starter.For more control on mypy behaviour, you could use flags, for example:
I am closing this, since this is unlikely to change. Feel free to re-open if you have additional concerns.
dgoldstein0 commentedon Apr 20, 2017
so I understand that it is expected for unchecked imports to be Any - but what I did not expect is that we could use one of them as a type without any warning. It doesn't sound like any of those flags you are suggesting will fix this? Can we please reopen? (It doesn't look like I have the ability to do this myself)
anyhow I filed this task at the suggestion of @ddfisher, who thought a flag for a warning about this could be valuable
ilevkivskyi commentedon Apr 20, 2017
Yes, this case is not covered by current flags. And it looks like such flag is not too difficult to implement.
[-]using a type from an unanalyzed file to be a mypy error[/-][+]Add flag prohibiting annotation by Any resulting from an unanalyzed module[/+]Revert PR python#3205 and python#3235
Revert reveal_type message fix (#3267)
ddfisher commentedon May 18, 2017
(assigning to myself to hold for @ilinum)
ddfisher commentedon May 18, 2017
As some additional background, this happens when the
--follow-imports=skipand--ignore-missing-importsflags are set.To implement this, I'd start by adding an additional member to the
AnyTypeclass which tracks whether or not it's from a silent import. I'd then grep forignore_missing_importsandfollow_importsto find where ignored module imports are turned intoAnys, and set the member I'd added toAnyTypethere.Next, I'd add the new
--disallow-implicit-any-typesflag. It needs to be added toprocess_optionsinmain.pyand toOptionsinoptions.py. It should be a per-module option.For the warning itself, I'd add checks to
visit_func_def,visit_overloaded_func_defandvisit_class_definchecker.py.Finally, I'd add several tests for this functionality to the end of
check-flags.test.Add flag to disallow implicit Any types.
Add flag to disallow implicit Any types.
Add flag to disallow implicit Any types.