Skip to content

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

Python
1
2
3
4
from typing import Any

def process_data(data: Any) -> str:
    return str(data)
Unsoundness Checker Output
Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
warning[typing-any-used]: Using `typing.Any` in type annotations can lead to runtime errors.
 --> main.py:3:24
  |
1 | from typing import Any
2 |
3 | def process_data(data: Any) -> str:
  |                        ^^^
4 |     return str(data)
  |
info: rule `typing-any-used` was selected in the configuration file

Mypy: No Diagnostic Emitted

Pyright: No Diagnostic Emitted

Ty: No Diagnostic Emitted

Return types

Python
1
2
3
4
from typing import Any

def get_user_data() -> Any:
    return {"name": "John", "age": 30}
Unsoundness Checker Output
Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
warning[typing-any-used]: Using `typing.Any` in type annotations can lead to runtime errors.
 --> main.py:3:24
  |
1 | from typing import Any
2 |
3 | def get_user_data() -> Any:
  |                        ^^^
4 |     return {"name": "John", "age": 30}
  |
info: rule `typing-any-used` was selected in the configuration file

Mypy: No Diagnostic Emitted

Pyright: No Diagnostic Emitted

Ty: No Diagnostic Emitted

Variable assignments

Python
1
2
3
4
5
6
from typing import Any

def get_user() -> dict[str, str | int]:
    return {"name": "John", "age": 30}

user_info: Any = get_user()
Unsoundness Checker Output
Text Only
1
2
3
4
5
6
7
8
9
warning[typing-any-used]: Using `typing.Any` in type annotations can lead to runtime errors.
 --> main.py:6:12
  |
4 |     return {"name": "John", "age": 30}
5 |
6 | user_info: Any = get_user()
  |            ^^^
  |
info: rule `typing-any-used` was selected in the configuration file

Mypy: No Diagnostic Emitted

Pyright: No Diagnostic Emitted

Ty: No Diagnostic Emitted