bpack.typing module
bpack support for type annotations.
- class bpack.typing.T(*args, **kwargs)[source]
Bases:
object
Allow 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.Annotated
numeric type with attached abpack.typing.TypeParams
instance.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:
NamedTuple
Named tuple describing type parameters.
- byteorder: EByteOrder | None
Alias for field number 0
- 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.Annotated
type annotation of a basic numeric type with attached abpack.typing.TypeParams
instance.See also