typedparser 0.31.3__tar.gz → 0.32.1__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.31.3
3
+ Version: 0.32.1
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
@@ -25,4 +25,4 @@ __all__ = [
25
25
  ]
26
26
 
27
27
 
28
- __version__ = "0.31.3"
28
+ __version__ = "0.32.1"
@@ -105,6 +105,7 @@ def modify_nested_object(
105
105
  modifier_fn: Callable,
106
106
  return_copy: bool = False,
107
107
  parser_class: Type[RecursorInterface] = StrictRecursor,
108
+ tuple_to_list: bool = False,
108
109
  ) -> Any:
109
110
  """
110
111
  Traverse a python object and apply a modifier function to all leaves.
@@ -116,6 +117,7 @@ def modify_nested_object(
116
117
  modifier_fn: modifier function to apply to all leaves
117
118
  return_copy: whether to copy the object before modifying it
118
119
  parser_class: which parser to use for iterable and mapping checks
120
+ tuple_to_list: if True, convert tuples to lists
119
121
 
120
122
  Examples:
121
123
  >>> e_dict = {'a': 1, 'b': {'c': 2, 'd': 3}}
@@ -126,16 +128,17 @@ def modify_nested_object(
126
128
 
127
129
  """
128
130
  parser = parser_class()
131
+ tuple_type = list if tuple_to_list else tuple
132
+ if return_copy:
133
+ d = deepcopy(d)
129
134
 
130
135
  def _modify_nested_object(d_inner: Any, depth: int = 0) -> Any:
131
136
  recursive_fn = partial(_modify_nested_object, depth=depth + 1)
132
- if return_copy:
133
- d_inner = deepcopy(d_inner)
134
137
  if parser.is_mapping_fn(d_inner):
135
138
  for k, v in d_inner.items():
136
139
  d_inner[k] = recursive_fn(v)
137
140
  elif isinstance(d_inner, tuple): # tuple does not support in-place modification
138
- d_inner = tuple(recursive_fn(v) for v in d_inner)
141
+ d_inner = tuple_type(recursive_fn(v) for v in d_inner)
139
142
  elif isinstance(d_inner, set): # set does not support in-place modification
140
143
  d_inner = set(recursive_fn(v) for v in d_inner)
141
144
  elif parser.is_iterable_fn(d_inner):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.31.3
3
+ Version: 0.32.1
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
File without changes
File without changes
File without changes