ruff/docs/rules/dynamically-typed-expression.md

513 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 type that can be anything, and it is the default type for unannotated expressions. It is better to be explicit about the type of an expression, and to use Any only when it is really needed.

Example

def foo(x: Any):
    ...

Use instead:

def foo(x: int):
    ...