Task: Add modern Python type hints to the following code. Follow these rules:
- Annotate all function parameters and return types
- Use built-in generics (e.g.,
list[str]
notList[str]
) - Use
|
for unions instead ofUnion
(Python 3.10+ style) - Add
-> None
for void returns - Import required types ONLY when needed
- Preserve original functionality exactly
- For ambiguous types, use:
Any
for completely unknown types
TypeVar
for generic relationships