dolor.types.util

Type utilities.

prepare_type(obj)[source]

Ensures an object is a Type.

Parameters

obj (subclass of Type or collections.abc.Mapping) –

If a subclass of Type, then that is simply returned.

If a collections.abc.Mapping (e.g. a dict), then a VersionSwitchedType is returned with obj as the switch.

Otherwise an error is raised.

Returns

The corresponding type.

Return type

subclass of Type

Raises

ValueError – If obj cannot be converted to a Type.

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 Type are passed through prepare_type() before being forwarded onto the function. This works for *args and **kwargs as well.