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
-> Nonefor void returns - Import required types ONLY when needed
- Preserve original functionality exactly
- For ambiguous types, use:
Anyfor completely unknown types
TypeVarfor generic relationships