pane.types
pane.types
Helper types for use with pane.convert
and dataclasses.
Num = t.TypeVar('Num', bound=t.Union[int, float])
module-attribute
PositiveInt = t.Annotated[int, Positive]
module-attribute
NonNegativeInt = t.Annotated[int, NonNegative]
module-attribute
NegativeInt = t.Annotated[int, Negative]
module-attribute
NonPositiveInt = t.Annotated[int, NonPositive]
module-attribute
PositiveFloat = t.Annotated[float, Positive]
module-attribute
NonNegativeFloat = t.Annotated[float, NonNegative]
module-attribute
NegativeFloat = t.Annotated[float, Negative]
module-attribute
NonPositiveFloat = t.Annotated[float, NonPositive]
module-attribute
FiniteFloat = t.Annotated[float, Finite]
module-attribute
ListNotEmpty = t.Annotated[t.List[T], len_range(min=1)]
module-attribute
Range
Source code in pane/types.py
start
instance-attribute
end
instance-attribute
n = field(default=None)
class-attribute
instance-attribute
step = field(default=None, kw_only=True)
class-attribute
instance-attribute
_converter(*args, handlers)
classmethod
Source code in pane/classes.py
make_unchecked(*args, **kwargs)
classmethod
from_dict_unchecked(d, *, set_fields=None)
classmethod
from_obj(obj, *, custom=None)
classmethod
Convert obj
into cls
. Equivalent to convert(obj, cls)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Convertible
|
Object to convert. Must be convertible. |
required |
Source code in pane/classes.py
from_data(data, *, custom=None)
classmethod
Convert data
into cls
. Equivalent to from_data(data, cls)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
DataType
|
Data to convert. Must be a data interchange type. |
required |
Source code in pane/classes.py
into_data(*, custom=None)
dict(*, set_only=False, rename=None)
Return a dict of the fields in self
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set_only
|
bool
|
If |
False
|
rename
|
Optional[RenameStyle]
|
Rename fields to match the given style |
None
|
Source code in pane/classes.py
from_json(f, *, custom=None)
classmethod
Load cls
from a JSON file f
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
FileOrPath
|
File-like or path-like to load from |
required |
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
from_yaml(f, *, custom=None)
classmethod
Load cls
from a YAML file f
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
FileOrPath
|
File-like or path-like to load from |
required |
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
from_yaml_all(f, *, custom=None)
classmethod
Load a list of cls
from a YAML file f
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
FileOrPath
|
File-like or path-like to load from |
required |
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
from_yamls(s, *, custom=None)
classmethod
Load cls
from a YAML string s
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
YAML string to load from |
required |
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
from_jsons(s, *, custom=None)
classmethod
Load cls
from a JSON string s
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
JSON string to load from |
required |
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
write_json(f=None, *, indent=None, sort_keys=False, custom=None)
Write data to a JSON file or string. If given a file f
, write to that.
Otherwise, write to a string and return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
Union[str, int, None]
|
Indent to format JSON with. Defaults to None (no indentation) |
None
|
sort_keys
|
bool
|
Whether to sort keys prior to serialization. |
False
|
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
write_yaml(f=None, *, indent=None, width=None, allow_unicode=True, explicit_start=True, explicit_end=False, default_style=None, default_flow_style=None, sort_keys=False, custom=None)
write_yaml(f: io.FileOrPath, *, indent: t.Optional[int] = None, width: t.Optional[int] = None, allow_unicode: bool = True, explicit_start: bool = True, explicit_end: bool = False, default_style: t.Optional[t.Literal['"', '|', '>']] = None, default_flow_style: t.Optional[bool] = None, sort_keys: bool = False, custom: t.Optional[IntoConverterHandlers] = None) -> None
write_yaml(f: None = None, *, indent: t.Optional[int] = None, width: t.Optional[int] = None, allow_unicode: bool = True, explicit_start: bool = True, explicit_end: bool = False, default_style: t.Optional[t.Literal['"', '|', '>']] = None, default_flow_style: t.Optional[bool] = None, sort_keys: bool = False, custom: t.Optional[IntoConverterHandlers] = None) -> str
Write data to a YAML file or string. If given a file f
, write to that.
Otherwise, write to a string and return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
Optional[int]
|
Number of spaces to indent blocks with |
None
|
width
|
Optional[int]
|
Maximum width of file created |
None
|
allow_unicode
|
bool
|
Whether to output unicode characters or escape them |
True
|
explicit_start
|
bool
|
Whether to include a YAML document start "---" |
True
|
explicit_end
|
bool
|
Whether to include a YAML document end "..." |
False
|
default_style
|
Optional[Literal['"', '|', '>']]
|
Default style to use for scalar nodes. See YAML documentation for more information. |
None
|
default_flow_style
|
Optional[bool]
|
Whether to default to flow style or block style for collections. See YAML documentation for more information. |
None
|
sort_keys
|
bool
|
Whether to sort keys prior to serialization. |
False
|
custom
|
Optional[IntoConverterHandlers]
|
Custom converters to use |
None
|
Source code in pane/classes.py
ValueOrList
Bases: Generic[T]
Source code in pane/types.py
from_val(val)
classmethod
from_list(list_val)
classmethod
_converter(*args, handlers)
classmethod
ValueOrListConverter
Bases: UnionConverter
Source code in pane/types.py
types = tuple(flatten_union_args(types))
instance-attribute
List of potential types
converters = tuple(make_converter(ty, handlers) for ty in types)
instance-attribute
List of type converters
constructor = constructor
instance-attribute
Constructor to call with parsed value.
Called with (val, index of type in union)
ty = ty
instance-attribute
convert(val)
Convert val
to T_co
. Raises a ConvertError
on failure.