argsloader.units.operator¶
PipeUnit¶
-
class
argsloader.units.operator.
PipeUnit
(*units: argsloader.units.base.BaseUnit)[source]¶ - Overview:
Unit for pipe all the units together.
-
__init__
(*units: argsloader.units.base.BaseUnit)[source]¶ Constructor of
PipeUnit
.- Parameters
units – Unit to be piped together.
>> operator¶
-
argsloader.units.operator.
_cpipe
(*units) → argsloader.units.operator.PipeUnit[source]¶ - Overview:
Pipe the units together, and latter one will receive the former one’s output result.
- Parameters
units – Units to be piped together, should be no less than 1 unit.
- Returns
A piped unit.
- Examples::
Simple pipe usage
>>> from argsloader.units import add, mul, interval >>> u = add.by(2) >> mul.by(3) # (x + 2) * 3 >>> u(3) 15 >>> u(10) 36
Use with a check unit
>>> u = add.by(2) >> interval.lR(3, 11) # x + 2, then check (3, 11] >>> u(3) 5 >>> u(10) ValueParseError: Value not in interval - (3, 11] expected but 12 found.
Warning
The function
_cpipe()
is not recommended being used directly, operator>>
should be used instead.
AndUnit¶
-
class
argsloader.units.operator.
AndUnit
(*units: argsloader.units.base.BaseUnit)[source]¶ - Overview:
Unit for chain all the units with
and
logic together.
-
__init__
(*units: argsloader.units.base.BaseUnit)[source]¶ Constructor of
PipeUnit
.- Parameters
units – Unit to be chained with
and
logic together.
& operator¶
-
argsloader.units.operator.
_cand
(*units) → argsloader.units.operator.AndUnit[source]¶ - Overview:
Chain the units with
and
logic together, all the units will be checked together.
- Parameters
units – Units to be chained together, should be no less than 1 unit.
- Returns
A and-chained unit.
- Examples::
>>> from argsloader.units import is_type, interval >>> u = is_type(int) & interval.lR(3, 10) >>> u(3) ValueParseError: Value not in interval - (3, 10] expected but 3 found. >>> u(10) 10 >>> u(3.0) TypeParseError: Value type not match - int expected but float found.
Note
If all the units in
AndUnit
have succeeded, the last unit’s result will be the final result of thisAndUnit
. For example,>>> from argsloader.units import is_type, interval, add >>> u = is_type(int) & (add.by(2) >> interval.lR(5, 12)) >>> u(10) 12
Note
All the units in
AndUnit
will be executed, and all the errors will be displayed when methodargsloader.units.base.BaseUnit.call()
is called. For example,>>> from argsloader.units import is_type, interval >>> u = is_type(int) & interval.lR(3, 10) >>> u.call(3) argsloader.base.exception.MultipleParseError: (1 error) <root>: ValueParseError: Value not in interval - (3, 10] expected but 3 found. >>> u.call(10) 10 >>> u.call(3.0) argsloader.base.exception.MultipleParseError: (2 errors) <root>: TypeParseError: Value type not match - int expected but float found. <root>: ValueParseError: Value not in interval - (3, 10] expected but 3.0 found.
Warning
The function
_cand()
is not recommended being used directly, operator&
should be used instead.
OrUnit¶
-
class
argsloader.units.operator.
OrUnit
(*units: argsloader.units.base.BaseUnit)[source]¶ - Overview:
Unit for chain all the units with
or
logic together.
-
__init__
(*units: argsloader.units.base.BaseUnit)[source]¶ Constructor of
PipeUnit
.- Parameters
units – Unit to be chained with
or
logic together.
| operator¶
-
argsloader.units.operator.
_cor
(*units) → argsloader.units.operator.OrUnit[source]¶ - Overview:
Chain the units with
or
logic together, all the units will be checked together.
- Parameters
units – Units to be chained together, should be no less than 1 unit.
- Returns
A or-chained unit.
- Examples::
>>> from argsloader.units import is_type, interval >>> u = is_type(int) | interval.lR(3, 10) >>> u(3) 3 >>> u(10) 10 >>> u(3.0) TypeParseError: Value type not match - int expected but float found.
Note
The processing process will be terminated once one unit has succeeded, the latter units will be skipped, and the success unit’s return value will be used as the final result. For example,
>>> from argsloader.units import is_type, interval, add, mul >>> u = (mul.by(3) >> is_type(int)) | (add.by(2) >> interval.lR(5, 12)) >>> u(10) # 10 * 3 30 >>> u(6.0) # 6.0 + 2 8.0
Note
If all the units in
AndUnit
have failed, all the errors will be displayed when methodargsloader.units.base.BaseUnit.call()
is called. For example,>>> from argsloader.units import is_type, interval >>> u = is_type(int) | interval.lR(3, 10) >>> u.call(3) 3 >>> u.call(10) 10 >>> u.call(3.0) argsloader.base.exception.MultipleParseError: (2 errors) <root>: TypeParseError: Value type not match - int expected but float found. <root>: ValueParseError: Value not in interval - (3, 10] expected but 3.0 found.
Warning
The function
_cor()
is not recommended being used directly, operator|
should be used instead.