Skip to content

--warn-return-any is too specialized #2901

Closed
@JukkaL

Description

@JukkaL

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 is Any (or object).
  • Assigning an Any value to a variable with an Any / object type seems okay as well.
  • Narrowing down from an Any value using isinstance or cast should be allowed.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions