typespecs.typing module#

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.

If the object is an instance, this function retrieves the annotations from its class rather than the instance itself.

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.