typespecs.typing module#

class typespecs.typing.HasAnnotations(*args, **kwargs)[source]#

Bases: Protocol

Type hint for any object with annotations.

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

Return metadata-stripped annotation of given object.

Parameters:
  • obj – Object to inspect.

  • recursive – Whether to recursively strip all metadata.

Returns:

Metadata-stripped annotation of the object.

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

Return all annotations of given object.

Prior to Python 3.14, this is identical to typing_extensions.get_annotations. For Python 3.14 and later, it falls back to the object’s class if __annotations__ is missing.

Parameters:

obj – Object to inspect.

Returns:

Dictionary of all annotations of the object.

typespecs.typing.get_metadata(obj: Any, /) list[Any][source]#

Return all metadata of given object.

Parameters:

obj – Object to inspect.

Returns:

List of all metadata of the object.

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

Return all sub-annotations of given object.

Parameters:

obj – Object to inspect.

Returns:

List of all sub-annotations of the object.

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

Check if given object has metadata.

Parameters:

obj – Object to inspect.

Returns:

True if the object has metadata. False otherwise.

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

Check if given object is a literal type.

Parameters:

obj – Object to inspect.

Returns:

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