MCPcopy
hub / github.com/openai/openai-python / deepcopy_with_paths

Function deepcopy_with_paths

src/openai/_files.py:128–145  ·  view source on GitHub ↗

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]])

Source from the content-addressed store, hash-verified

126
127
128def 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
148def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:

Calls 1

_deepcopy_with_pathsFunction · 0.85