typing.Any
used
Detects usage of typing.Any
in type annotations, which can lead to runtime errors by bypassing type checking.
When you use Any
, you're essentially telling the type checker "this could be anything," which defeats the purpose of having types in the first place. This can cause bugs that would otherwise be caught at development time.
What gets flagged
We currently detect Any
in these places:
Function parameters
Diagnostic Output
Return types
Diagnostic Output
Variable assignments
Diagnostic Output
Why this matters
Using Any
removes type safety. For example:
Diagnostic Output
Instead, be specific about what you expect:
No Diagnostic Emitted
Other Examples
The checker also finds Any
nested in other types:
from typing import Any
def process(data: dict[str, Any]) -> None: pass
def get_items() -> list[Any]: pass
user_data: dict[str, Any] = {}
Diagnostic Output
error[typing-any-used]: Using `typing.Any` in type annotations can lead to runtime errors.
--> snippet_06.py:3:29
|
1 | from typing import Any
2 |
3 | def process(data: dict[str, Any]) -> None: pass
| ^^^
4 | def get_items() -> list[Any]: pass
5 | user_data: dict[str, Any] = {}
|
info: rule `typing-any-used` is enabled by default
error[typing-any-used]: Using `typing.Any` in type annotations can lead to runtime errors.
--> snippet_06.py:4:25
|
3 | def process(data: dict[str, Any]) -> None: pass
4 | def get_items() -> list[Any]: pass
| ^^^
5 | user_data: dict[str, Any] = {}
|
info: rule `typing-any-used` is enabled by default
error[typing-any-used]: Using `typing.Any` in type annotations can lead to runtime errors.
--> snippet_06.py:5:22
|
3 | def process(data: dict[str, Any]) -> None: pass
4 | def get_items() -> list[Any]: pass
5 | user_data: dict[str, Any] = {}
| ^^^
|
info: rule `typing-any-used` is enabled by default