pane.annotations
pane.annotations
Annotations supported by pane.convert()
and dataclasses.
Positive = adjective_condition(lambda v: v > 0, 'positive')
module-attribute
Condition
indicating value must be positive
Negative = adjective_condition(lambda v: v < 0, 'negative')
module-attribute
Condition
indicating value must be negative
NonPositive = adjective_condition(lambda v: v <= 0, 'non-positive')
module-attribute
Condition
indicating value must be non-positive
NonNegative = adjective_condition(lambda v: v >= 0, 'non-negative')
module-attribute
Condition
indicating value must be non-negative
Finite = adjective_condition(math.isfinite, 'finite')
module-attribute
Condition
indicating value must be finite
Empty = adjective_condition(lambda v: len(v) == 0, 'empty')
module-attribute
Condition
indicating value must be empty (have no elements)
NonEmpty = adjective_condition(lambda v: len(v) != 0, 'non-empty')
module-attribute
Condition
indicating value must not be empty
ConvertAnnotation
Abstract annotation supported by pane
.
Source code in pane/annotations.py
Tagged
dataclass
Bases: ConvertAnnotation
Source code in pane/annotations.py
tag
instance-attribute
Name of tag. This name will be searched in every Union member
external = False
class-attribute
instance-attribute
Tagged unions can be stored three ways
- Internally tagged (
external=False
, default). In this format, the tags are stored inside of each object:{tag_name: tag_value, **obj}
- Externally tagged (
external=True
). In this format, the tag is stored as a key outside the rest of the object:{tag_value: obj}
- Adjacently tagged (
external=(tag_key, value_key)
). In this format, the tag and value are stored under separate items:{tag_key: tag_value, value_key: obj}
This specification affects conversion into and out symmetrically.
_converter(inner_type, *, handlers)
Source code in pane/annotations.py
Condition
dataclass
Bases: ConvertAnnotation
Source code in pane/annotations.py
f
instance-attribute
Condition/predicate function.
This is called with a parsed value, and should return True
if it passes the condition.
name = None
class-attribute
instance-attribute
Human-readable name of this condition
make_expected = None
class-attribute
instance-attribute
Given an inner expected
string, and a boolean indicating plurality, this should return a
formatted expected
string including the condition.
This is a low-level function that can be overrided for better error messages.
all(*conditions, make_expected=None)
staticmethod
Create a condition by and
ing together multiple conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
Condition
|
Conditions to combine |
()
|
make_expected
|
Optional[Callable[[str, bool], str]]
|
If specified, override |
None
|
Source code in pane/annotations.py
any(*conditions, make_expected=None)
staticmethod
Create a condition by or
ing together multiple conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conditions
|
Condition
|
Conditions to combine |
()
|
make_expected
|
Optional[Callable[[str, bool], str]]
|
If specified, override |
None
|
Source code in pane/annotations.py
cond_name()
_converter(inner_type, *, handlers)
Source code in pane/annotations.py
val_range(*, min=None, max=None)
Condition
indicating that a value must be between min
and max
(inclusive).
Source code in pane/annotations.py
len_range(*, min=None, max=None)
Condition
indicating that a value must have between min
and max
elements (inclusive).
Source code in pane/annotations.py
shape(shape)
Condition
indicating that a value must have a shape shape
.
Fails on objects that don't have a shape
attribute.
Source code in pane/annotations.py
broadcastable(shape)
Condition
indicating that a value must be broadcastable to shape shape
.
Fails on objects that don't have a shape
attribute.
Source code in pane/annotations.py
adjective_condition(f, adjective, article='a')
Make a condition that can be expressed as a simple adjective (e.g. 'empty' or 'non-empty').
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Callable[[Any], bool]
|
Condition/predicate function |
required |
adjective
|
str
|
Adjective corresponding to |
required |
article
|
str
|
Article to put in front of |
'a'
|