pytools.typing#

Utilities for run-time type inference.

Functions#

get_common_generic_base

Get the most specific common type of the given objects.

get_common_generic_subclass

Get the most general common subclass of the given classes.

get_generic_bases

Extended version of typing_inspect.get_generic_bases that covers some special cases for generic instances of generic aliases.

get_generic_instance

Given a subclass and a generic base class, get the generic instances of the base class, substituting all type arguments along the class hierarchy.

get_type_arguments

Given an object and a generic base class, get the type arguments of the base class, substituting all type arguments along the class hierarchy.

isinstance_generic

Check if an object is an instance of a generic instance, i.e., it is a subclass of the generic class, and has compatible type arguments.

issubclass_generic

Check if a class is a subclass of a generic instance, i.e., it is a subclass of the generic class, and has compatible type arguments.