Copy only the containers along the given paths. Used to guard against mutation by extract_files without copying the entire structure. Only dicts and lists that lie on a path are copied; everything else is returned by reference. For example, given paths=[["foo", "files", "file"]] an
(item: _T, paths: Sequence[Sequence[str]])
| 126 | |
| 127 | |
| 128 | def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T: |
| 129 | """Copy only the containers along the given paths. |
| 130 | |
| 131 | Used to guard against mutation by extract_files without copying the entire structure. |
| 132 | Only dicts and lists that lie on a path are copied; everything else |
| 133 | is returned by reference. |
| 134 | |
| 135 | For example, given paths=[["foo", "files", "file"]] and the structure: |
| 136 | { |
| 137 | "foo": { |
| 138 | "bar": {"baz": {}}, |
| 139 | "files": {"file": <content>} |
| 140 | } |
| 141 | } |
| 142 | The root dict, "foo", and "files" are copied (they lie on the path). |
| 143 | "bar" and "baz" are returned by reference (off the path). |
| 144 | """ |
| 145 | return _deepcopy_with_paths(item, paths, 0) |
| 146 | |
| 147 | |
| 148 | def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T: |