From adb258ceff1e847b38561252d4ced7061f66c45d Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Mon, 6 May 2024 09:41:51 -0500 Subject: [PATCH 1/3] Made the pop_disconnected method more reliable. --- src/ophydregistry/registry.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ophydregistry/registry.py b/src/ophydregistry/registry.py index c25a3f9..120f546 100644 --- a/src/ophydregistry/registry.py +++ b/src/ophydregistry/registry.py @@ -3,11 +3,16 @@ import warnings from collections import OrderedDict from itertools import chain -from typing import List, Mapping, Optional, Set +from typing import List, Mapping, Optional, Set, Hashable from weakref import WeakSet, WeakValueDictionary from ophyd import ophydobj +try: + from pcdsdevices.signal import _AggregateSignalState +except ImportError: + _AggregateSignalState = ophydobj + # Sentinal value for default parameters UNSET = object() @@ -115,7 +120,7 @@ class Registry: use_typhos: bool keep_references: bool _auto_register: bool - _valid_classes: Set[type] = {ophydobj.OphydObject} + _valid_classes: Set[type] = {ophydobj.OphydObject, _AggregateSignalState} # components: Sequence _objects_by_name: Mapping @@ -195,11 +200,12 @@ def pop(self, key, default=UNSET) -> ophydobj.OphydObject: # Remove from the list by name try: del self._objects_by_name[obj.name] - except KeyError: + except (KeyError, AttributeError): pass # Remove from the list by label - for objects in self._objects_by_label.values(): - objects.discard(obj) + if isinstance(obj, Hashable): + for objects in self._objects_by_label.values(): + objects.discard(obj) # Remove children from the lists as well sub_signals = getattr(obj, "_signals", {}) for cpt_name, cpt in sub_signals.items(): From 73c7280a8aaeb2efa1fd16fedfa60c47d2bd76e1 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Mon, 6 May 2024 10:15:14 -0500 Subject: [PATCH 2/3] Fixed tests, plus black, isort, flake8. --- src/ophydregistry/registry.py | 13 ++++++------- src/ophydregistry/tests/test_instrument_registry.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ophydregistry/registry.py b/src/ophydregistry/registry.py index 120f546..1ba6bc3 100644 --- a/src/ophydregistry/registry.py +++ b/src/ophydregistry/registry.py @@ -3,7 +3,7 @@ import warnings from collections import OrderedDict from itertools import chain -from typing import List, Mapping, Optional, Set, Hashable +from typing import Hashable, List, Mapping, Optional, Tuple from weakref import WeakSet, WeakValueDictionary from ophyd import ophydobj @@ -11,7 +11,7 @@ try: from pcdsdevices.signal import _AggregateSignalState except ImportError: - _AggregateSignalState = ophydobj + _AggregateSignalState = ophydobj.OphydObject # Sentinal value for default parameters UNSET = object() @@ -120,7 +120,7 @@ class Registry: use_typhos: bool keep_references: bool _auto_register: bool - _valid_classes: Set[type] = {ophydobj.OphydObject, _AggregateSignalState} + _valid_classes: Tuple[type] = (ophydobj.OphydObject, _AggregateSignalState) # components: Sequence _objects_by_name: Mapping @@ -200,7 +200,7 @@ def pop(self, key, default=UNSET) -> ophydobj.OphydObject: # Remove from the list by name try: del self._objects_by_name[obj.name] - except (KeyError, AttributeError): + except (KeyError, AttributeError): pass # Remove from the list by label if isinstance(obj, Hashable): @@ -352,9 +352,8 @@ def _is_resolved(self, obj): ``_valid_classes`` attribute with a new set. """ - for cls in self._valid_classes: - if isinstance(obj, cls): - return True + if isinstance(obj, self._valid_classes): + return True return False def _findall_by_label(self, label, allow_none): diff --git a/src/ophydregistry/tests/test_instrument_registry.py b/src/ophydregistry/tests/test_instrument_registry.py index 0cac3fb..54add3b 100644 --- a/src/ophydregistry/tests/test_instrument_registry.py +++ b/src/ophydregistry/tests/test_instrument_registry.py @@ -13,7 +13,7 @@ @pytest.fixture() def registry(): reg = Registry(auto_register=False, use_typhos=False) - reg._valid_classes = {mock.MagicMock, *reg._valid_classes} + reg._valid_classes = (mock.MagicMock, *reg._valid_classes) try: yield reg finally: From f331359e150bb47408ec66f5530feb0baf044a97 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Mon, 6 May 2024 10:16:21 -0500 Subject: [PATCH 3/3] Version bump to v1.2.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 47881ba..cace22e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ophyd-registry" -version = "1.2.0" +version = "1.2.1" authors = [ { name="Mark Wolfman", email="wolfman@anl.gov" }, ]