It is becoming increasingly common in modern Python codebases—especially in libraries and frameworks—to use general abstractions like Mapping and Sequence for type hints, rather than concrete types like dict and list.
It allows your functions to accept any object that behaves like a mapping or sequence, not just built-in dict or list.
This makes the library code more flexible, extensible, and compatible with a wider range of inputs (e.g., custom mapping/sequence types, collections.defaultdict, tuple, etc.).
It is recommended in the official Python typing documentation.
For example, change
column_to_attr: Dict[int, str]
skip_columns: Optional[list[int]]
tables: List[List[List[str]]]
to:
from typing import Mapping, Sequence
column_to_attr: Mapping[int, str]
skip_columns: Optional[Sequence[int]]
tables: Sequence[Sequence[Sequence[str]]]
It is becoming increasingly common in modern Python codebases—especially in libraries and frameworks—to use general abstractions like Mapping and Sequence for type hints, rather than concrete types like dict and list.
It allows your functions to accept any object that behaves like a mapping or sequence, not just built-in dict or list.
This makes the library code more flexible, extensible, and compatible with a wider range of inputs (e.g., custom mapping/sequence types, collections.defaultdict, tuple, etc.).
It is recommended in the official Python typing documentation.
For example, change
to: