diff --git a/src/pymadng/madp_classes.py b/src/pymadng/madp_classes.py index 402f0bb..d66bb82 100644 --- a/src/pymadng/madp_classes.py +++ b/src/pymadng/madp_classes.py @@ -1,3 +1,4 @@ +import warnings # To warn the user when they try to deepcopy a mad_ref from typing import Iterable, Union, Any # To make stuff look nicer import numpy as np from .madp_pymad import mad_process, mad_ref, type_str, is_private @@ -94,6 +95,17 @@ def __dir__(self) -> Iterable[str]: """) return [x for x in self._mad.recv() if isinstance(x, str) and x[0] != "_"] + def __deepcopy__(self, memo): + val = self.eval() + if isinstance(val, list): + for i, v in enumerate(val): + if isinstance(v, mad_ref): + val[i] = v.__deepcopy__(memo) + elif isinstance(val, type(self)) and val._name == self._name: + warnings.warn("An attempt to deepcopy a mad_ref has been made, this is not supported and will result in a copy of the reference.") + return val + + class madhl_obj(madhl_ref): def __dir__(self) -> Iterable[str]: diff --git a/src/pymadng/madp_pymad.py b/src/pymadng/madp_pymad.py index 4b4015c..826c628 100644 --- a/src/pymadng/madp_pymad.py +++ b/src/pymadng/madp_pymad.py @@ -1,4 +1,4 @@ -import struct, os, subprocess, sys, select, warnings, io +import struct, os, subprocess, sys, select from typing import Union, Callable, Any import numpy as np @@ -178,17 +178,6 @@ def __getitem__(self, item: Union[str, int]): def eval(self): return self._mad.recv_vars(self._name) - def __deepcopy__(self, memo): - - val = self.eval() - if isinstance(val, list): - for i, v in enumerate(val): - if isinstance(v, mad_ref): - val[i] = v.__deepcopy__(memo) - elif isinstance(val, type(self)) and val._name == self._name: - warnings.warn("An attempt to deepcopy a mad_ref has been made, this is not supported and will result in a copy of the reference.") - return val - # data transfer -------------------------------------------------------------- # # Data ----------------------------------------------------------------------- #