Closed
Description
Recently the --warn-return-any
option was added which causes mypy to warn if returning a value with an Any
type (#2854). @ddfisher pointed out the this is not very general:
Thinking out loud here: this helps catch accidental Anys in one particular circumstance, but it might be nice to have something a bit more comprehensive as well. Perhaps we should consider adding a flag which disallows use of Any-typed values except as the right hand side of an assignment with a type comment (i.e. forcing all Anys to be immediately typed).
I agree that #2854 seems too narrowly focused. I like @ddfisher's suggestion, with a few tweaks:
Any
should probably be okay as a function argument type if the argument type isAny
(orobject
).- Assigning an
Any
value to a variable with anAny
/object
type seems okay as well. - Narrowing down from an
Any
value usingisinstance
orcast
should be allowed.