Typing: Compatibility#
Since typing still significantly changes across different Python versions, all the special cases are handled here.
- tad_mctc.typing.compat.CacheKey#
alias of
tuple[int,str,tuple[Any, …],frozenset[tuple[str,Any]]]
- class tad_mctc.typing.compat.Sequence#
All the operations on a read-only sequence.
Concrete subclasses must override __new__ or __init__, __getitem__, and __len__.
- count(value) integer -- return number of occurrences of value#
- index(value[, start[, stop]]) integer -- return first index of value.#
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- tad_mctc.typing.compat.override(arg, /)[source]#
Indicate that a method is intended to override a method in a base class.
Usage:
- class Base:
- def method(self) -> None:
pass
- class Child(Base):
@override def method(self) -> None:
super().method()
When this decorator is applied to a method, the type checker will validate that it overrides a method with the same name on a base class. This helps prevent bugs that may occur when a base class is changed without an equivalent change to a child class.
There is no runtime checking of these properties. The decorator sets the
__override__attribute toTrueon the decorated object to allow runtime introspection.See PEP 698 for details.