typedload Module to check types, mostly from the typing module.
For example is_list(List) and is_list(List[int]) return True.
It is not the same as isinstance(), it wants types, not instances.
It is expected that is_list(list) returns False, since it shouldn't be used for type hints.
The module is useful because there is no public API to do those checks, and it protects the user from the ever changing internal representation used in different versions of Python.
Functions
is_any
Check if it is a typing.Any
is_pattern
Check if the type is a re.Pattern
is_attrs
Check if the type is obtained with an
@attr.s decorator
is_dataclass
check if it's generated with dataclass decorator
is_dict
Dict[A, B]
Dict
is_enum
Check if the class is a subclass of Enum
is_forwardref
Check if it's a ForwardRef.
They are unresolved types passed as strings, supposed to
be resolved into types at a later moment
is_frozenset
FrozenSet[A]
FrozenSet
is_list
List[A]
List
is_literal
Check if the type is a typing.Literal
is_namedtuple
Generated with typing.NamedTuple
is_nonetype
type_ == type(None)
is_set
Set[A]
Set
is_tuple
Tuple[int, str]
Tuple
is_union
Union[A, B]
Union
Optional[A]
A | B
is_typeddict
Check if it is a typing.TypedDict
is_optional
Optional[int]
int | None
Note that Optional is just a Union, so if is_optional is True then
also is_union will be True
is_notrequired
Check if it's typing.NotRequired or typing_extensions.NotRequired
is_required
Check if it's typing.Required or typing_extensions.Required
notrequiredtype
Return the type wrapped by Required/NotRequired
notrequiredtype
Return the type wrapped by Required/NotRequired
uniontypes
Returns the types of a Union.
literalvalues
Returns the values of a Literal
Raises ValueError if the argument is not a Literal