bpack.typing module
bpack support for type annotations.
- class bpack.typing.T(*args, **kwargs)[source]
Bases:
objectAllow to specify numeric type annotations using string descriptors.
Example:
>>> T['u4'] typing.Annotated[int, TypeParams(byteorder=None, type='int', size=4, signed=False)]
The resulting type annotation is a
typing.Annotatednumeric type with attached abpack.typing.TypeParamsinstance.String descriptors, or typestr, are compatible with numpy (a sub-set of one used in the numpy “array interface”).
The typestr string format consists of 3 parts:
an (optional) character describing the byte order of the data
<: little-endian,>: big-endian,|: not-relevant
a character code giving the basic type of the array, and
an integer providing the number of bytes the type uses
The basic type character codes are:
i: sighed integeru: unsigned integerf: floatc: complexS: bytes (string)
Note
typestr the format described above is a sub-set of the one used in the numpy “array interface”.
See also
str_to_type_params(),TypeParams, https://numpy.org/doc/stable/reference/arrays.dtypes.html and https://numpy.org/doc/stable/reference/arrays.interface.html
- class bpack.typing.TypeParams(byteorder: EByteOrder | None, type: type[bool | int | float | complex | bytes | str], size: int | None, signed: bool | None)[source]
Bases:
NamedTupleNamed tuple describing type parameters.
- byteorder: EByteOrder | None
Alias for field number 0
- signed: bool | None
Alias for field number 3
- size: int | None
Alias for field number 2
- type: type[bool | int | float | complex | bytes | str]
Alias for field number 1
- bpack.typing.is_annotated(type_: type) bool[source]
Return True if the input is an annotated numeric type.
An annotated numeric type is assumed to be a
typing.Annotatedtype annotation of a basic numeric type with attached abpack.typing.TypeParamsinstance.See also