-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Problem
Using Any
is not type safe, therefore Mypy provides options to disallow Any
. However, there are many uses of Any
from third-party and stdlib, so these options tend to result in a lot of errors even when they are not relevant.
I'm finding many situations where I get an error about Any
, but the code would be deemed safe if it was object
.
Examples
This produces errors about Any
on both lines even though the value is not used:
type_hints = typing.get_type_hints(...) # Dict[str, Any]
if k in type_hints:
...
This produces errors as well, but object
would not produce errors, as Mypy can infer everything necessary here to be type safe.
origin = typing.get_origin(...) # Any
if origin is Literal:
...
elif origin is list:
...
Solution
Add an option, or change the behaviour of the current disallow Any
options, such that Any
is treated like object
. Then, rather than producing errors when Any
is present, just show normal errors with Any
(as if it was object
) in them (e.g. 'Any has no attribute foo').