Skip to content

emit a warning for "unused Any" #20078

@wyattscarpenter

Description

@wyattscarpenter

A common problem afflicting novices getting into python static type annotations is that they assume Any is the top type in Python, like how Never is its bottom type. Hence, they use Any too much, where it is not necessary.

I think we should emit a warning when an explicit Any annotation is used but didn't have to be, much like what we do for warn-redundant-casts.

In fact, I think there are three related warnings we should emit:

  1. If Any is used but object would have worked
  2. If Any is used but mypy was able to deduce a type that worked (using the regular mypy deduction)
  3. If there is a Callable special form with ... (Ellipsis) in place of the list of parameter types (basically just another way to spell Any, see https://typing.python.org/en/latest/spec/callables.html#meaning-of-in-callable) but one of the previous two cases holds

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions