typedparser 0.11.2__tar.gz → 0.11.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.11.2
3
+ Version: 0.11.4
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
@@ -150,6 +150,7 @@ print(attrs_from_dict(CfgNested, {"sub_cfg": {"foo": 1, "bar": 2}}))
150
150
  the output will be a tuple
151
151
  * Raise errors if types cannot be matched, there are unknown fields in the input or
152
152
  abstract annotation types are used (e.g. Sequence)
153
+ * Set `_allow_extra_keys = True` in the class definition to allow unknown fields in the input
153
154
 
154
155
  ### Non-strict mode
155
156
 
@@ -123,6 +123,7 @@ print(attrs_from_dict(CfgNested, {"sub_cfg": {"foo": 1, "bar": 2}}))
123
123
  the output will be a tuple
124
124
  * Raise errors if types cannot be matched, there are unknown fields in the input or
125
125
  abstract annotation types are used (e.g. Sequence)
126
+ * Set `_allow_extra_keys = True` in the class definition to allow unknown fields in the input
126
127
 
127
128
  ### Non-strict mode
128
129
 
@@ -28,5 +28,5 @@ def define(*args, **kwargs):
28
28
  )
29
29
 
30
30
 
31
- __version__ = "0.11.2"
31
+ __version__ = "0.11.4"
32
32
 
@@ -229,7 +229,7 @@ def _attrs_from_dict(
229
229
 
230
230
  # handle unknown fields
231
231
  if len(nonmatching_input) > 0 and not skip_unknowns:
232
- if strict:
232
+ if strict and not getattr(cls, "_allow_extra_keys", False):
233
233
  raise TypeError(
234
234
  f"Keys in input {list(nonmatching_input.keys())} not defined "
235
235
  f"for class {cls} with attributes {sorted(all_att_names)}"
@@ -315,7 +315,7 @@ def _parse_nested(
315
315
  )
316
316
 
317
317
  # resolve any
318
- if typ == Any:
318
+ if typ in [Any, any]:
319
319
  return value
320
320
 
321
321
  # resolve unions (mostly "optional")
@@ -369,9 +369,9 @@ def _parse_nested(
369
369
  dict_output = {}
370
370
 
371
371
  for key, val in value.items():
372
- dict_output[parse_recursive(name, key, dict_keytype, strict=strict)] = parse_recursive(
373
- name, val, dict_valuetype, strict=strict
374
- )
372
+ parsed_key = parse_recursive(f"{name}/dict_key_type", key, dict_keytype, strict=strict)
373
+ parsed_value = parse_recursive(f"{name}/{key}", val, dict_valuetype, strict=strict)
374
+ dict_output[parsed_key] = parsed_value
375
375
 
376
376
  return dict_output
377
377
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.11.2
3
+ Version: 0.11.4
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
@@ -150,6 +150,7 @@ print(attrs_from_dict(CfgNested, {"sub_cfg": {"foo": 1, "bar": 2}}))
150
150
  the output will be a tuple
151
151
  * Raise errors if types cannot be matched, there are unknown fields in the input or
152
152
  abstract annotation types are used (e.g. Sequence)
153
+ * Set `_allow_extra_keys = True` in the class definition to allow unknown fields in the input
153
154
 
154
155
  ### Non-strict mode
155
156
 
File without changes
File without changes