dolor.types.util¶
Type utilities.
- prepare_type(obj)[source]¶
Ensures an object is a
Type.- Parameters
obj (subclass of
Typeorcollections.abc.Mapping) –If a subclass of
Type, then that is simply returned.If a
collections.abc.Mapping(e.g. adict), then aVersionSwitchedTypeis returned withobjas the switch.Otherwise an error is raised.
- Returns
The corresponding type.
- Return type
subclass of
Type- Raises
ValueError – If
objcannot be converted to aType.
Examples
>>> import dolor >>> dolor.types.prepare_type(dolor.types.VarInt) <class 'dolor.types.numeric.VarInt'> >>> dolor.types.prepare_type({}) <class 'dolor.types.version.VersionSwitchedType'>
- prepare_types(func)[source]¶
A decorator that passes certain arguments are passed through
prepare_type().Arguments annotated with
Typeare passed throughprepare_type()before being forwarded onto the function. This works for*argsand**kwargsas well.