argsloader.units.type

IsTypeUnit

class argsloader.units.type.IsTypeUnit(type_)[source]
Overview:

Unit for checking the data’s type.

__init__(type_)[source]

Constructor of IsTypeUnit.

Parameters

type – Type unit.

is_type

argsloader.units.type.is_type(type_)argsloader.units.type.IsTypeUnit[source]
Overview:

Check if the input data is an instance of the given type.

Parameters

type – Type or type unit.

Returns

A is-type unit object.

Examples::
>>> from argsloader.units import is_type
>>> u = is_type(int)
>>> u(1)
1
>>> u(1.0)
TypeParseError: Value type not match - int expected but float found.

ToTypeUnit

class argsloader.units.type.ToTypeUnit(type_)[source]
Overview:

Unit for transforming the input data to the given type.

__init__(type_)[source]

Constructor of ToTypeUnit.

Parameters

type – Type unit.

to_type

argsloader.units.type.to_type(type_)argsloader.units.type.ToTypeUnit[source]
Overview:

Turn the input data to the given type.

Parameters

type – Type or type unit.

Returns

A to-type unit object.

Examples::
>>> from argsloader.units import to_type
>>> u = to_type(int)
>>> u(1)
1
>>> u(1.2)
1

IsSubclassUnit

class argsloader.units.type.IsSubclassUnit(type_)[source]
Overview:

Unit for checking if the object is subclass of the given type.

__init__(type_)[source]

Constructor of IsSubclassUnit.

Parameters

type – Type unit.

is_subclass

argsloader.units.type.is_subclass(type_)argsloader.units.type.IsSubclassUnit[source]
Overview:

Check if the input is a subclass of the given type_.

Parameters

type – Type unit.

Returns

A is-subclass unit object.

Examples::
>>> from argsloader.units import is_subclass
>>> class A(dict): pass
...
>>> u = is_subclass(dict)
>>> u(dict)
<class 'dict'>
>>> u(A)
<class '__main__.A'>
>>> u(int)
TypeParseError: Value type not match - dict's subclass expected but type found.