pane.classes
pane.classes
Pane dataclasses.
PaneBaseT = t.TypeVar('PaneBaseT', bound='PaneBase')
module-attribute
ClassLayout = t.Literal['tuple', 'struct']
module-attribute
Set of known class layouts for 'in_formats' and 'out_format'.
PANE_INFO = '__pane_info__'
module-attribute
Name of dunder attribute holding PaneInfo
PANE_SET_FIELDS = '__pane_set__'
module-attribute
Name of dunder attribute holding a set of fields which have been set/modified
PANE_BOUNDVARS = '__pane_boundvars__'
module-attribute
Name of dunder attribute holding a dictionary of bound type variables (for generic subclasses only).
POST_INIT = '__post_init__'
module-attribute
Name of post-init method
Field
dataclass
Represents a materialized dataclass field.
Typically instantiated from a FieldSpec
.
Source code in pane/field.py
name
instance-attribute
Name of field
type
instance-attribute
Type of field. Must be Convertible
.
in_names
instance-attribute
List of names which convert to this field.
out_name
instance-attribute
Name this field converts into.
init = True
class-attribute
instance-attribute
Whether to add this field to init methods (and conversion from other types)
exclude = False
class-attribute
instance-attribute
Whether to exclude this field when converting to other types
repr = True
class-attribute
instance-attribute
Whether to include this field in repr
hash = True
class-attribute
instance-attribute
Whether to include this field in the generated hash method
compare = True
class-attribute
instance-attribute
Whether to include this field in generated comparison methods (eq, gt, etc.)
default = _MISSING
class-attribute
instance-attribute
Default value for field
default_factory = None
class-attribute
instance-attribute
Default value factory for field
kw_only = False
class-attribute
instance-attribute
Whether field is keyword only
converter = None
class-attribute
instance-attribute
Custom converter to use for this field.
make(name, ty, in_rename=None, out_rename=None)
classmethod
Source code in pane/field.py
PaneBase
Base class for all pane
dataclasses
Source code in pane/classes.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
_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
PaneInfo
dataclass
Structure holding internal information about a pane
dataclass
Source code in pane/classes.py
PaneOptions
dataclass
Source code in pane/classes.py
name = None
class-attribute
instance-attribute
Dataclass name
eq = True
class-attribute
instance-attribute
Whether to generate __eq__
/__ne__
methods
order = True
class-attribute
instance-attribute
Whether to generate __gt__
/__ge__
/__lt__
/__le__
methods
frozen = True
class-attribute
instance-attribute
Whether dataclass fields are frozen
unsafe_hash = False
class-attribute
instance-attribute
Whether to generate a hash method
kw_only = False
class-attribute
instance-attribute
Whether all fields should be keyword-only
out_format = 'struct'
class-attribute
instance-attribute
Data format to convert class into
in_format = ('struct',)
class-attribute
instance-attribute
Set of data formats class is convertible from
in_rename = None
class-attribute
instance-attribute
Set of rename styles class is convertible from
out_rename = None
class-attribute
instance-attribute
Rename style to convert class into
allow_extra = False
class-attribute
instance-attribute
Whether extra fields are allowed in conversion
class_handlers = ()
class-attribute
instance-attribute
Custom converters to use for field datatypes
replace(**changes)
Return self
with the given changes applied
PaneConverter
Converter
for pane
dataclasses
Source code in pane/classes.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
|
cls = cls
instance-attribute
name = self.cls.__name__
instance-attribute
cls_info = getattr(self.cls, PANE_INFO)
instance-attribute
opts = self.cls_info.opts
instance-attribute
fields = self.cls_info.fields
instance-attribute
field_converters = [field.converter if field.converter is not None else make_converter(field.type, handlers) for field in self.fields]
instance-attribute
field_map = {}
instance-attribute
convert(val)
Convert val
to T_co
. Raises a ConvertError
on failure.
Source code in pane/converters.py
into_data(val)
Convert dataclass val
into data interchange, using the correct 'out_format'
Source code in pane/classes.py
expected(plural=False)
try_convert(val)
Dispatches to try_convert_tuple
and try_convert_struct
Source code in pane/classes.py
collect_errors(val)
Dispatches to collect_errors_tuple
and collect_errors_struct
Source code in pane/classes.py
expected_struct(plural=False)
try_convert_struct(val)
Converter.try_convert
for the 'struct' data format
Source code in pane/classes.py
collect_errors_struct(val)
Converter.collect_errors
for the 'struct' data format
Source code in pane/classes.py
expected_tuple(plural=False)
try_convert_tuple(val)
Converter.try_convert
for the 'tuple' data format
Source code in pane/classes.py
collect_errors_tuple(val)
Converter.collect_errors
for the 'tuple' data format
Source code in pane/classes.py
field(*, rename=None, in_names=None, aliases=None, out_name=None, init=True, exclude=False, repr=True, hash=None, compare=True, default=_MISSING, default_factory=None, kw_only=False, converter=None)
field(*, rename: t.Optional[str] = None, in_names: None = None, aliases: None = None, out_name: t.Optional[str] = None, init: bool = True, exclude: bool = False, repr: bool = True, hash: t.Optional[bool] = None, compare: bool = True, default: t.Union[T, _Missing] = _MISSING, default_factory: t.Optional[t.Callable[[], T]] = None, kw_only: bool = False, converter: t.Optional[Converter[T]] = None) -> t.Any
field(*, rename: None = None, in_names: t.Sequence[str], aliases: None = None, out_name: t.Optional[str] = None, init: bool = True, exclude: bool = False, repr: bool = True, hash: t.Optional[bool] = None, compare: bool = True, default: t.Union[T, _Missing] = _MISSING, default_factory: t.Optional[t.Callable[[], T]] = None, kw_only: bool = False, converter: t.Optional[Converter[T]] = None) -> t.Any
field(*, rename: None = None, in_names: None = None, aliases: t.Sequence[str], out_name: t.Optional[str] = None, init: bool = True, exclude: bool = False, repr: bool = True, hash: t.Optional[bool] = None, compare: bool = True, default: t.Union[T, _Missing] = _MISSING, default_factory: t.Optional[t.Callable[[], T]] = None, kw_only: bool = False, converter: t.Optional[Converter[T]] = None) -> t.Any
field(*, rename: t.Optional[str] = None, in_names: t.Optional[t.Sequence[str]] = None, aliases: t.Optional[t.Sequence[str]] = None, out_name: t.Optional[str] = None, init: bool = True, exclude: bool = False, repr: bool = True, hash: t.Optional[bool] = None, compare: bool = True, default: t.Union[T, _Missing] = _MISSING, default_factory: t.Optional[t.Callable[[], T]] = None, kw_only: bool = False, converter: t.Optional[Converter[T]] = None) -> t.Any
Annotate a dataclass field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rename
|
Optional[str]
|
Name to rename this field as. Used for both input and output. Useful when a field name should be different inside vs. outside of Python. |
None
|
in_names
|
Optional[Sequence[str]]
|
List of names which should convert into this field. If specified, the field name inside Python will be excluded (unlike |
None
|
aliases
|
Optional[Sequence[str]]
|
List of aliases (additional names) for this field. Includes the field name inside Python (unlike |
None
|
out_name
|
Optional[str]
|
Name which this field should convert into. |
None
|
init
|
bool
|
If |
True
|
exclude
|
bool
|
If |
False
|
repr
|
bool
|
Whether to include this field in the generated repr method. |
True
|
hash
|
Optional[bool]
|
Whether to include this field in the generated hash method. Defaults to |
None
|
compare
|
bool
|
Whether to include this field in generated comparison methods ( |
True
|
default
|
Union[T, _Missing]
|
Default value for field |
_MISSING
|
default_factory
|
Optional[Callable[[], T]]
|
Default value factory for field |
None
|
kw_only
|
bool
|
Whether the field is keyword-only. |
False
|