typespecs.typing module#

typespecs.typing.del_metadata(annotation: Any, /, *, recursive: bool = False) Any[source]#

Return metadata-stripped annotation.

Parameters:
  • annotation – Annotation to strip metadata from.

  • recursive – Whether to recursively strip metadata of sub-annotations.

Returns:

Metadata-stripped annotation.

typespecs.typing.get_annotation(annotation: Any, /, *, recursive: bool = False) Any[source]#

Return metadata-stripped annotation.

Parameters:
  • annotation – Annotation to strip metadata from.

  • recursive – Whether to recursively strip metadata of sub-annotations.

Returns:

Metadata-stripped annotation.

typespecs.typing.get_annotations(cls_or_obj: Any, /) dict[str, Any][source]#

Return annotations of given class or object.

If it is a class instance, this function tries to retrieve the annotations from its class rather than the instance itself.

Parameters:

cls_or_obj – Class or object to inspect.

Returns:

Dictionary of annotations of the class or object.

typespecs.typing.get_metadata(annotation: Any, /, *, type: None = None) list[Any][source]#
typespecs.typing.get_metadata(annotation: Any, /, *, type: type[T]) list[T]

Return metadata of given annotation.

Parameters:
  • annotation – Annotation to inspect.

  • type – Type of metadata to filter. If specified, only metadata of the given type will be returned. Otherwise, all metadata will be returned.

Returns:

List of metadata of the annotation.

typespecs.typing.get_subannotations(annotation: Any, /) list[Any][source]#

Return sub-annotations of given annotation.

Parameters:

annotation – Annotation to inspect.

Returns:

List of sub-annotations of the annotation.

typespecs.typing.has_metadata(annotation: Any, /) bool[source]#

Check if given annotation has metadata.

Parameters:

annotation – Annotation to inspect.

Returns:

True if the annotation has metadata. False otherwise.

typespecs.typing.is_literal(annotation: Any, /) bool[source]#

Check if given annotation is a literal type.

Parameters:

annotation – Annotation to inspect.

Returns:

True if the annotation is a literal type. False otherwise.