Minimal reimplementation of copy.deepcopy() that will only copy certain object types: - mappings, e.g. `dict` - list This is done for performance reasons.
(item: _T)
| 178 | |
| 179 | |
| 180 | def deepcopy_minimal(item: _T) -> _T: |
| 181 | """Minimal reimplementation of copy.deepcopy() that will only copy certain object types: |
| 182 | |
| 183 | - mappings, e.g. `dict` |
| 184 | - list |
| 185 | |
| 186 | This is done for performance reasons. |
| 187 | """ |
| 188 | if is_mapping(item): |
| 189 | return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()}) |
| 190 | if is_list(item): |
| 191 | return cast(_T, [deepcopy_minimal(entry) for entry in item]) |
| 192 | return item |
| 193 | |
| 194 | |
| 195 | # copied from https://github.com/Rapptz/RoboDanny |