typedparser 0.31.2__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.
- {typedparser-0.31.2 → typedparser-0.32.1}/PKG-INFO +1 -1
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser/__init__.py +1 -1
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser/objects.py +11 -2
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser.egg-info/PKG-INFO +1 -1
- {typedparser-0.31.2 → typedparser-0.32.1}/LICENSE +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/README.md +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/pyproject.toml +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/requirements.txt +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/setup.cfg +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser/_typedattr.py +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser/_typedparser.py +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser/custom_format.py +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser/funcs.py +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser.egg-info/SOURCES.txt +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser.egg-info/dependency_links.txt +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser.egg-info/requires.txt +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser.egg-info/top_level.txt +0 -0
- {typedparser-0.31.2 → typedparser-0.32.1}/src/typedparser.egg-info/zip-safe +0 -0
|
@@ -105,15 +105,19 @@ 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.
|
|
111
112
|
|
|
113
|
+
Note: This also modifies tuples and sets.
|
|
114
|
+
|
|
112
115
|
Args:
|
|
113
116
|
d: object to modify (e.g. dict)
|
|
114
117
|
modifier_fn: modifier function to apply to all leaves
|
|
115
118
|
return_copy: whether to copy the object before modifying it
|
|
116
119
|
parser_class: which parser to use for iterable and mapping checks
|
|
120
|
+
tuple_to_list: if True, convert tuples to lists
|
|
117
121
|
|
|
118
122
|
Examples:
|
|
119
123
|
>>> e_dict = {'a': 1, 'b': {'c': 2, 'd': 3}}
|
|
@@ -124,14 +128,19 @@ def modify_nested_object(
|
|
|
124
128
|
|
|
125
129
|
"""
|
|
126
130
|
parser = parser_class()
|
|
131
|
+
tuple_type = list if tuple_to_list else tuple
|
|
132
|
+
if return_copy:
|
|
133
|
+
d = deepcopy(d)
|
|
127
134
|
|
|
128
135
|
def _modify_nested_object(d_inner: Any, depth: int = 0) -> Any:
|
|
129
136
|
recursive_fn = partial(_modify_nested_object, depth=depth + 1)
|
|
130
|
-
if return_copy:
|
|
131
|
-
d_inner = deepcopy(d_inner)
|
|
132
137
|
if parser.is_mapping_fn(d_inner):
|
|
133
138
|
for k, v in d_inner.items():
|
|
134
139
|
d_inner[k] = recursive_fn(v)
|
|
140
|
+
elif isinstance(d_inner, tuple): # tuple does not support in-place modification
|
|
141
|
+
d_inner = tuple_type(recursive_fn(v) for v in d_inner)
|
|
142
|
+
elif isinstance(d_inner, set): # set does not support in-place modification
|
|
143
|
+
d_inner = set(recursive_fn(v) for v in d_inner)
|
|
135
144
|
elif parser.is_iterable_fn(d_inner):
|
|
136
145
|
for i, v in enumerate(d_inner):
|
|
137
146
|
d_inner[i] = recursive_fn(v)
|
|
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
|