mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
848 B
848 B
dynamically-typed-expression (ANN401)
Derived from the flake8-annotations linter.
What it does
Checks that an expression is annotated with a more specific type than
Any
.
Why is this bad?
Any
is a special type indicating an unconstrained type. When an
expression is annotated with type Any
, type checkers will allow all
operations on it.
It's better to be explicit about the type of an expression, and to use
Any
as an "escape hatch" only when it is really needed.
Example
def foo(x: Any):
...
Use instead:
def foo(x: int):
...