typedparser 0.10.4__tar.gz → 0.10.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {typedparser-0.10.4 → typedparser-0.10.5}/PKG-INFO +1 -1
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser/__init__.py +1 -1
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser/_typedattr.py +26 -8
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser.egg-info/PKG-INFO +1 -1
- {typedparser-0.10.4 → typedparser-0.10.5}/LICENSE +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/README.md +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/pyproject.toml +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/requirements.txt +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/setup.cfg +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser/_typedparser.py +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser/custom_format.py +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser/funcs.py +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser/objects.py +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser.egg-info/SOURCES.txt +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser.egg-info/dependency_links.txt +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser.egg-info/requires.txt +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser.egg-info/top_level.txt +0 -0
- {typedparser-0.10.4 → typedparser-0.10.5}/src/typedparser.egg-info/zip-safe +0 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import attrs
|
|
1
2
|
import collections
|
|
3
|
+
from attr import has, AttrsInstance
|
|
4
|
+
from attrs import define, fields_dict, fields, Attribute
|
|
2
5
|
from functools import partial
|
|
3
6
|
from inspect import isclass
|
|
4
7
|
from pathlib import Path
|
|
@@ -15,13 +18,9 @@ from typing import (
|
|
|
15
18
|
List,
|
|
16
19
|
Optional,
|
|
17
20
|
get_type_hints,
|
|
18
|
-
Callable,
|
|
21
|
+
Callable,
|
|
19
22
|
)
|
|
20
23
|
|
|
21
|
-
import attrs
|
|
22
|
-
from attr import has, AttrsInstance
|
|
23
|
-
from attrs import define, fields_dict, fields, Attribute
|
|
24
|
-
|
|
25
24
|
from .objects import check_object_equality, RecursorInterface, StrictRecursor, AttrsClass
|
|
26
25
|
|
|
27
26
|
try:
|
|
@@ -133,7 +132,10 @@ def _attrs_from_dict(
|
|
|
133
132
|
skip_unknowns: bool = False,
|
|
134
133
|
conversions: Optional[conversion_type] = None,
|
|
135
134
|
more_error_info: str = "",
|
|
135
|
+
current_position: Optional[List] = None,
|
|
136
136
|
):
|
|
137
|
+
if current_position is None:
|
|
138
|
+
current_position = []
|
|
137
139
|
_print_fn(f"Parsing {cls} from {input_dict_or_attrs}")
|
|
138
140
|
input_cls = type(input_dict_or_attrs)
|
|
139
141
|
if has(input_cls):
|
|
@@ -173,7 +175,7 @@ def _attrs_from_dict(
|
|
|
173
175
|
for field_name, field_value in matching_input.items():
|
|
174
176
|
field_att = cls_fields_dict[field_name]
|
|
175
177
|
try:
|
|
176
|
-
is_positional = bool(field_att.default == attrs.NOTHING)
|
|
178
|
+
is_positional = bool(field_att.default == attrs.NOTHING) and not field_att.kw_only
|
|
177
179
|
except ValueError:
|
|
178
180
|
# some field defaults, e.g. numpy arrays do not have comparison defined here
|
|
179
181
|
# but that means that the default is set and the field is not positional
|
|
@@ -185,7 +187,17 @@ def _attrs_from_dict(
|
|
|
185
187
|
|
|
186
188
|
# create an attrs instance from the dict
|
|
187
189
|
# the instance will be flat (nested dicts are not resolved yet) and not typechecked.
|
|
188
|
-
|
|
190
|
+
try:
|
|
191
|
+
cls_inst = cls(*in_args, **in_kwargs) # noqa
|
|
192
|
+
attrs_inst = cls_inst
|
|
193
|
+
# # not sure why evolve was used before
|
|
194
|
+
# attrs_inst = attrs.evolve(cls_inst, **in_kwargs) # noqa
|
|
195
|
+
except TypeError as e:
|
|
196
|
+
raise TypeError(
|
|
197
|
+
f"Failed creating instance of {cls} from input {input_dict} "
|
|
198
|
+
f"with args {in_args} and kwargs {in_kwargs}. Error occurred at: "
|
|
199
|
+
f"{'.'.join(current_position)}. {e}\n\nError context: {more_error_info}."
|
|
200
|
+
) from e
|
|
189
201
|
|
|
190
202
|
# typecheck and unfold nested values in the attrs instance
|
|
191
203
|
type_hints = get_type_hints(cls)
|
|
@@ -205,6 +217,7 @@ def _attrs_from_dict(
|
|
|
205
217
|
skip_unknowns=skip_unknowns,
|
|
206
218
|
conversions=conversions,
|
|
207
219
|
more_error_info=more_error_info,
|
|
220
|
+
current_position=current_position + [name],
|
|
208
221
|
)
|
|
209
222
|
setattr(attrs_inst, name, new_value)
|
|
210
223
|
|
|
@@ -242,14 +255,17 @@ def _parse_nested(
|
|
|
242
255
|
conversions: conversion_type = None,
|
|
243
256
|
depth: int = 0,
|
|
244
257
|
more_error_info: str = "",
|
|
258
|
+
current_position: Optional[List] = None,
|
|
245
259
|
):
|
|
246
260
|
conversions = default_conversions if conversions is None else conversions
|
|
247
261
|
parse_recursive = partial(
|
|
248
262
|
_parse_nested,
|
|
249
263
|
recursor,
|
|
250
|
-
depth=depth + 1,
|
|
251
264
|
skip_unknowns=skip_unknowns,
|
|
265
|
+
conversions=conversions,
|
|
266
|
+
depth=depth + 1,
|
|
252
267
|
more_error_info=more_error_info,
|
|
268
|
+
current_position=current_position,
|
|
253
269
|
)
|
|
254
270
|
|
|
255
271
|
if isinstance(typ, str):
|
|
@@ -288,6 +304,8 @@ def _parse_nested(
|
|
|
288
304
|
strict=strict,
|
|
289
305
|
skip_unknowns=skip_unknowns,
|
|
290
306
|
conversions=conversions,
|
|
307
|
+
more_error_info=more_error_info,
|
|
308
|
+
current_position=current_position,
|
|
291
309
|
)
|
|
292
310
|
|
|
293
311
|
# resolve any
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|