typedparser 0.10.6__tar.gz → 0.11.2__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.6 → typedparser-0.11.2}/PKG-INFO +2 -2
- {typedparser-0.10.6 → typedparser-0.11.2}/README.md +1 -1
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser/__init__.py +1 -1
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser/_typedattr.py +24 -14
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser.egg-info/PKG-INFO +2 -2
- {typedparser-0.10.6 → typedparser-0.11.2}/LICENSE +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/pyproject.toml +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/requirements.txt +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/setup.cfg +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser/_typedparser.py +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser/custom_format.py +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser/funcs.py +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser/objects.py +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser.egg-info/SOURCES.txt +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser.egg-info/dependency_links.txt +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser.egg-info/requires.txt +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser.egg-info/top_level.txt +0 -0
- {typedparser-0.10.6 → typedparser-0.11.2}/src/typedparser.egg-info/zip-safe +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: typedparser
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.2
|
|
4
4
|
Summary: Extension for python argparse with typehints and typechecks.
|
|
5
5
|
Author: simon-ging
|
|
6
6
|
License: Apache-2.0
|
|
@@ -181,7 +181,7 @@ Note: Some tests are skipped for python 3.7.
|
|
|
181
181
|
|
|
182
182
|
~~~bash
|
|
183
183
|
pip install -e .
|
|
184
|
-
pip install pytest pytest-cov pylint
|
|
184
|
+
pip install pytest pytest-cov pylint
|
|
185
185
|
pylint typedparser
|
|
186
186
|
|
|
187
187
|
# run tests
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import attrs
|
|
2
1
|
import collections
|
|
3
|
-
from attr import has, AttrsInstance
|
|
4
|
-
from attrs import define, fields_dict, fields, Attribute
|
|
5
2
|
from functools import partial
|
|
6
3
|
from inspect import isclass
|
|
7
4
|
from pathlib import Path
|
|
@@ -21,8 +18,16 @@ from typing import (
|
|
|
21
18
|
Callable,
|
|
22
19
|
)
|
|
23
20
|
|
|
21
|
+
import attrs
|
|
22
|
+
from attr import has, AttrsInstance
|
|
23
|
+
from attrs import define, fields_dict, fields, Attribute
|
|
24
|
+
|
|
24
25
|
from .objects import check_object_equality, RecursorInterface, StrictRecursor, AttrsClass
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
from types import UnionType
|
|
29
|
+
except ImportError:
|
|
30
|
+
UnionType = None
|
|
26
31
|
|
|
27
32
|
try:
|
|
28
33
|
# python>=3.8
|
|
@@ -290,7 +295,7 @@ def _parse_nested(
|
|
|
290
295
|
# f" depth={depth} type annotation origin={origin} args={args}"
|
|
291
296
|
)
|
|
292
297
|
|
|
293
|
-
def
|
|
298
|
+
def maybe_raise_typeerror(full_err_msg):
|
|
294
299
|
if strict:
|
|
295
300
|
raise TypeError(full_err_msg)
|
|
296
301
|
_print_fn(f"Caught: {full_err_msg}. Returning as is.")
|
|
@@ -314,15 +319,20 @@ def _parse_nested(
|
|
|
314
319
|
return value
|
|
315
320
|
|
|
316
321
|
# resolve unions (mostly "optional")
|
|
317
|
-
if origin == Union or isinstance(typ, UnionType):
|
|
322
|
+
if origin == Union or (UnionType is not None and isinstance(typ, UnionType)):
|
|
323
|
+
collected_errors = []
|
|
318
324
|
for new_typ in args:
|
|
319
325
|
try:
|
|
320
326
|
# force strict parsing and catch errors to try all different types
|
|
321
327
|
return parse_recursive(name, value, new_typ, strict=True)
|
|
322
|
-
except TypeError:
|
|
323
|
-
|
|
328
|
+
except TypeError as e:
|
|
329
|
+
collected_errors.append(f"{e}")
|
|
324
330
|
# if we get here, none of the types worked
|
|
325
|
-
|
|
331
|
+
collected_error_str = "\n".join(collected_errors)
|
|
332
|
+
return maybe_raise_typeerror(
|
|
333
|
+
f"No type in Union matches. Errors per type:\n{collected_error_str}\n"
|
|
334
|
+
f"Final error: {err_msg}"
|
|
335
|
+
)
|
|
326
336
|
|
|
327
337
|
final_list_type = None
|
|
328
338
|
|
|
@@ -331,9 +341,9 @@ def _parse_nested(
|
|
|
331
341
|
if not (len(args) == 2 and args[1] == Ellipsis):
|
|
332
342
|
# resolve fixed tuple
|
|
333
343
|
if not recursor.is_iterable_fn(value):
|
|
334
|
-
return
|
|
344
|
+
return maybe_raise_typeerror(f"{err_msg}. Expect a sequence, got {type(value)}")
|
|
335
345
|
if len(value) != len(args):
|
|
336
|
-
return
|
|
346
|
+
return maybe_raise_typeerror(
|
|
337
347
|
f"{err_msg}. Expect a sequence with length {len(args)}, got length {len(value)}"
|
|
338
348
|
)
|
|
339
349
|
new_tuple = []
|
|
@@ -347,7 +357,7 @@ def _parse_nested(
|
|
|
347
357
|
# check dict
|
|
348
358
|
if origin in (dict, collections.defaultdict):
|
|
349
359
|
if not recursor.is_mapping_fn(value):
|
|
350
|
-
return
|
|
360
|
+
return maybe_raise_typeerror(f"{err_msg}. Expect a mapping, got {type(value)}")
|
|
351
361
|
if len(args) == 0:
|
|
352
362
|
args = [Any, Any]
|
|
353
363
|
dict_keytype, dict_valuetype = args
|
|
@@ -375,7 +385,7 @@ def _parse_nested(
|
|
|
375
385
|
# resolve list
|
|
376
386
|
if origin == list:
|
|
377
387
|
if not recursor.is_iterable_fn(value):
|
|
378
|
-
return
|
|
388
|
+
return maybe_raise_typeerror(f"{err_msg}. Expect iterable, got {type(value)}")
|
|
379
389
|
list_arg_type = args[0]
|
|
380
390
|
list_output = []
|
|
381
391
|
for item in value:
|
|
@@ -404,7 +414,7 @@ def _parse_nested(
|
|
|
404
414
|
except TypeError:
|
|
405
415
|
is_sc = False
|
|
406
416
|
if is_sc:
|
|
407
|
-
return
|
|
417
|
+
return maybe_raise_typeerror(f"{err_msg}. Abstract collections are not supported.")
|
|
408
418
|
|
|
409
419
|
# add explicit conversions
|
|
410
420
|
for convert_source, convert_target, convert_callable in conversions:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: typedparser
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.2
|
|
4
4
|
Summary: Extension for python argparse with typehints and typechecks.
|
|
5
5
|
Author: simon-ging
|
|
6
6
|
License: Apache-2.0
|
|
@@ -181,7 +181,7 @@ Note: Some tests are skipped for python 3.7.
|
|
|
181
181
|
|
|
182
182
|
~~~bash
|
|
183
183
|
pip install -e .
|
|
184
|
-
pip install pytest pytest-cov pylint
|
|
184
|
+
pip install pytest pytest-cov pylint
|
|
185
185
|
pylint typedparser
|
|
186
186
|
|
|
187
187
|
# run tests
|
|
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
|