Skip to content

Commit 7294566

Browse files
committed
fix: recurse into tuples in deepcopy_minimal to prevent mutation
deepcopy_minimal only copied dicts and lists, leaving tuples as-is. When a FileTypes tuple like (name, content, mime, headers) was passed to files.beta.upload, the headers Mapping inside the tuple could be mutated in-place, corrupting the caller's data. Fixes #1202
1 parent fbbc757 commit 7294566

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/anthropic/_utils/_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ def deepcopy_minimal(item: _T) -> _T:
181181
182182
- mappings, e.g. `dict`
183183
- list
184+
- tuple (recursed but preserved as tuple)
184185
185186
This is done for performance reasons.
186187
"""
187188
if is_mapping(item):
188189
return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()})
189190
if is_list(item):
190191
return cast(_T, [deepcopy_minimal(entry) for entry in item])
192+
if isinstance(item, tuple):
193+
return cast(_T, tuple(deepcopy_minimal(entry) for entry in item))
191194
return item
192195

193196

0 commit comments

Comments
 (0)