typing
Various type annotation aids.
Type Hints
Type hint for objects that represent filesystem paths. |
|
Invariant |
|
Type hint for numbers. |
|
The type of methods of some built-in data types and base classes. |
|
The type of bound methods of some built-in data types and base classes. |
|
The type of methods of some built-in data types. |
|
The type of unbound class methods of some built-in data types. |
-
PathLike
Type hint for objects that represent filesystem paths.
See also
-
PathType
= TypeVar(PathType, str, Path, PathLike) Type:
TypeVar
Invariant
TypeVar
constrained tostr
,pathlib.Path
andos.PathLike
.Type variable for objects that represent filesystem paths.
New in version 2.2.0.
See also
-
AnyNumber
Type hint for numbers.
Changed in version 0.4.6: Moved from
domdf_python_tools.pagesizes
-
WrapperDescriptorType
The type of methods of some built-in data types and base classes, such as
object.__init__()
orobject.__lt__()
.New in version 0.8.0.
-
MethodWrapperType
The type of bound methods of some built-in data types and base classes. For example, it is the type of
object().__str__
.New in version 0.8.0.
-
MethodDescriptorType
The type of methods of some built-in data types, such as
str.join()
.New in version 0.8.0.
-
ClassMethodDescriptorType
The type of unbound class methods of some built-in data types, such as
dict.__dict__['fromkeys']
.New in version 0.8.0.
Protocols
|
|
|
|
|
|
Invariant |
|
|
|
|
|
|
|
|
|
|
-
protocol
JsonLibrary
[source] Bases:
Protocol
typing.Protocol
for libraries that implement the same API asjson
.Useful for annotating functions which take a JSON serialisation-deserialisation library as an argument.
Classes that implement this protocol must have the following methods / attributes:
-
static
dumps
(obj, *, skipkeys=..., ensure_ascii=..., check_circular=..., allow_nan=..., cls=..., indent=..., separators=..., default=..., sort_keys=..., **kwds)[source] Serialize
obj
to a JSON formattedstr
.
-
static
loads
(s, *, cls=..., object_hook=..., parse_float=..., parse_int=..., parse_constant=..., object_pairs_hook=..., **kwds)[source] Deserialize
s
to a Python object.
-
static
-
protocol
HasHead
[source] Bases:
Protocol
typing.Protocol
for classes that have ahead
method.This includes
pandas.DataFrame
andpandas.Series
.New in version 0.8.0.
This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
-
protocol
String
[source] Bases:
Protocol
Protocol
for classes that implement__str__
.Changed in version 0.8.0: Moved from
domdf_python_tools.stringlist
.This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
-
protocol
FrameOrSeries
New in version 1.0.0.
Classes that implement this protocol must have the following methods / attributes:
-
protocol
SupportsIndex
[source] Bases:
Protocol
typing.Protocol
for classes that support__index__
.New in version 2.0.0.
Classes that implement this protocol must have the following methods / attributes:
-
protocol
SupportsLessThan
[source] Bases:
Protocol
typing.Protocol
for classes that support__lt__
.New in version 3.0.0.
Classes that implement this protocol must have the following methods / attributes:
-
protocol
SupportsLessEqual
[source] Bases:
Protocol
typing.Protocol
for classes that support__le__
.New in version 3.0.0.
Classes that implement this protocol must have the following methods / attributes:
-
protocol
SupportsGreaterThan
[source] Bases:
Protocol
typing.Protocol
for classes that support__gt__
.New in version 3.0.0.
Classes that implement this protocol must have the following methods / attributes:
Utility Functions
-
check_membership
(obj, type_)[source] Check if the type of
obj
is one of the types in atyping.Union
,typing.Sequence
etc.- Parameters
obj (
Any
) – The object to check the type oftype_ (
Union
[Type
,object
]) – AType
that has members, such as atyping.List
,typing.Union
ortyping.Sequence
.
- Return type