erdantic.typing_utils¶
get_depth1_bases
¶
Returns depth-1 base classes of a type.
Source code in erdantic/typing_utils.py
63 64 65 66 |
|
get_recursive_args
¶
get_recursive_args(tp: _TypeForm) -> List[_TypeForm]
Recursively finds leaf-node types of possibly-nested generic type.
Source code in erdantic/typing_utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
is_collection_type_of
¶
Given a type annotation, returns True if it represents a collection of many elements of the target type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tp |
Union[type, GenericAlias]
|
Type annotation. |
required |
target |
type
|
Type to check for many-ness of. |
required |
Returns:
Type | Description |
---|---|
bool
|
Result of check. |
Source code in erdantic/typing_utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
is_nullable_type
¶
is_nullable_type(tp: _TypeForm) -> bool
Given a type annotation, returns True if it is a union with None as a possible option, such as typing.Optional.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tp |
Union[type, GenericAlias]
|
Type annotation. |
required |
Returns:
Type | Description |
---|---|
bool
|
Result of check. |
Source code in erdantic/typing_utils.py
50 51 52 53 54 55 56 57 58 59 60 |
|
repr_type_with_mro
¶
Return MRO of object if it has one. Otherwise return its repr.
Source code in erdantic/typing_utils.py
95 96 97 98 99 100 101 102 103 104 105 |
|