Annotations#

register_annotations#

tkclasswiz.annotations.register_annotations(cls: type, mapping: dict | None = {}, **annotations)#

Extends original annotations of cls.

This can be useful eg. when the class your are adding is not part of your code and is also not annotated.

Classes that already have additional annotations:

  • datetime.timedelta

  • datetime.datetime

  • datetime.timezone

Parameters:
  • cls (type) – The class (or function) to register additional annotations on.

  • mapping (Optional[Dict[str, type]]) – Mapping mapping the parameter name to it’s type.

  • annotations (Optional[Unpack[str, type]]) – Keyword arguments mapping parameter name to it’s type (name=type).

Example

from datetime import timedelta, timezone

register_annotations(
    timezone,
    offset=timedelta,
    name=str
)

get_annotations#

tkclasswiz.annotations.get_annotations(class_) dict#

Returns class / function annotations including the ones extended with register_annotations. It does not return the return annotation.