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" }, ] diff --git a/src/ophydregistry/registry.py b/src/ophydregistry/registry.py index c25a3f9..1ba6bc3 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 Hashable, List, Mapping, Optional, Tuple from weakref import WeakSet, WeakValueDictionary from ophyd import ophydobj +try: + from pcdsdevices.signal import _AggregateSignalState +except ImportError: + _AggregateSignalState = ophydobj.OphydObject + # 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: Tuple[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(): @@ -346,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: