Skip to content

Commit 17d7616

Browse files
maarten-icolivhoenen
authored andcommitted
Bypass __setattr__ logic when creating a deepcopy
This improves deepcopy performance by ~40% for the ITER magnetics machine description.
1 parent bcd47fe commit 17d7616

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

imas/ids_structure.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This file is part of IMAS-Python.
22
# You should have received the IMAS-Python LICENSE file with this project.
3-
"""A structure in an IDS
4-
"""
3+
"""A structure in an IDS"""
54

65
import logging
76
from copy import deepcopy
@@ -151,7 +150,9 @@ def __deepcopy__(self, memo):
151150
for child in self._children:
152151
if child in self.__dict__:
153152
child_copy = deepcopy(getattr(self, child), memo)
154-
setattr(copy, child, child_copy)
153+
# bypass __setattr__:
154+
copy.__dict__[child] = child_copy
155+
child_copy._parent = copy
155156
return copy
156157

157158
def __dir__(self) -> List[str]:

0 commit comments

Comments
 (0)