How to Accept Any Type in a Python Type Hint with typing.Any
Type hints say what each value should be: name: str, count: int. Some values really can be anything, like the values of a settings dictionary that mixes text, numbers and flags. typing.Any is the hint for that. This guide hints a function and a dictionary with Any, with real output from Python 3.15.2.
Syntax
from typing import Any
def <function>(<parameter>: Any) -> <return type>: ...
<variable>: dict[str, Any] = {...}
| Part | What it means |
|---|---|
from typing import Any | Brings in Any. It isn't a built-in name |
<parameter>: Any | The parameter may receive a value of any type |
dict[str, Any] | A dictionary with string keys and values of any type |
Python's typing documentation: "Special type indicating an unconstrained type. Every type is assignable to Any. Any is assignable to every type."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
from typing import Any
def describe(value: Any) -> str:
return f"{value!r} ({type(value).__name__})"
settings: dict[str, Any] = {"theme": "dark", "retries": 3, "beta": True}
for key, value in settings.items():
print(key, "->", describe(value))

describe(value: Any)says the function accepts a value of any type, and returns astr.settings: dict[str, Any]says the keys are strings and the values can be anything.- The loop passes a
str, anintand aboolto the same function.
Step 2: Run It
uv run python typing_any.py
theme -> 'dark' (str)
retries -> 3 (int)
beta -> True (bool)

One function described three different types, and the hints said so honestly: Any for the parameter, dict[str, Any] for the settings. A reader, and a type checker, knows not to expect one particular type there.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Forgetting from typing import Any | The def still runs, because Python 3.14 and later evaluate hints only when something reads them. Then reading them fails: NameError: name 'Any' is not defined. Did you mean: 'any'? | Import it |
| Expecting the hint to check values when the code runs | Python doesn't enforce hints: double("ab") on a function hinted x: int returned 'abab' | Check values yourself where it matters |
Using Any where one type is known | Type checkers stop checking that value | Use the real type, and keep Any for values that can truly be anything |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
NameError: name 'Any' is not defined when a library reads your hints | Any wasn't imported | Add from typing import Any |
FAQ
Is any the same as Any?
No. Lowercase any() is a built-in function that checks whether any item in a list is true. The type hint is Any, from typing.
Can I hint a value that's one of a few types instead?
Yes, with |: int | str accepts an int or a str, which says more than Any.
Conclusion
value: Any and dict[str, Any] described honestly what describe() and the settings hold: values of any type, here a str, an int and a bool.
Additional Resources
- typing.Any — the unconstrained type.
