Junior — Middle
How do you verify the type of annotations in the code?
sobes.tech AI
Answer from AI
Checking annotation types in Python is usually done with static analyzers and type checking tools such as mypy, Pyright, or the built-in typing module.
Example:
from typing import List
def greet_all(names: List[str]) -> None:
for name in names:
print(f"Hello, {name}!")
# Type checking with mypy
To verify that annotations match actual types, run mypy:
mypy your_script.py
If types do not match, mypy will issue warnings. This helps catch errors before running the code.
You can also use the built-in isinstance() function for dynamic type checking at runtime, but this does not replace static annotation checking.