From 6ed67478328375c3c71a37d9f44122d89933cff8 Mon Sep 17 00:00:00 2001 From: Josh Meyers Date: Fri, 17 Nov 2023 11:50:21 -0800 Subject: [PATCH] Clean up CompoundOptic cached properties when inserting/removing items --- CHANGELOG.rst | 1 + batoid/_version.py | 2 +- batoid/optic.py | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2fb4ebd3..d5fb0199 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -26,3 +26,4 @@ Bug Fixes --------- - Allow random seeds in applicable RayVector contructors. - Trap divide-by-zero error in field_to_dircos +- Clean up CompoundOptic cached properties when inserting/removing items diff --git a/batoid/_version.py b/batoid/_version.py index ccf066e1..631dde28 100644 --- a/batoid/_version.py +++ b/batoid/_version.py @@ -1,6 +1,6 @@ #https://stackoverflow.com/a/7071358/7530778 -__version__ = "0.5.1" +__version__ = "0.5.2" tmp = __version__ if "rc" in tmp: # pragma: no cover tmp = tmp[:tmp.find("rc")] diff --git a/batoid/optic.py b/batoid/optic.py index 5ff04f92..bb96a1b6 100644 --- a/batoid/optic.py +++ b/batoid/optic.py @@ -1689,7 +1689,8 @@ def withInsertedOptic(self, before, item): raise ValueError("Optic {} not found".format(before)) newItems = [] newDict = dict(self.__dict__) - del newDict['items'] + for k in ['items', 'itemDict', '_names', 'R_inner', 'R_outer']: + newDict.pop(k, None) for i, it in enumerate(self.items): if self._names[it.name] == self._names[before]: newItems.append(item) @@ -1717,7 +1718,8 @@ def withRemovedOptic(self, item): raise ValueError("Optic {} not found".format(item)) newItems = [] newDict = dict(self.__dict__) - del newDict['items'] + for k in ['items', 'itemDict', '_names', 'R_inner', 'R_outer']: + newDict.pop(k, None) for it in self.items: if self._names[it.name] != self._names[item]: newItems.append(it)