Skip to content

Commit

Permalink
Merge pull request #6 from spc-group/pop_disconnected
Browse files Browse the repository at this point in the history
Improved the ``pop_disconnected()`` method.
  • Loading branch information
canismarko authored May 6, 2024
2 parents d78103c + f331359 commit 64b3a30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ophyd-registry"
version = "1.2.0"
version = "1.2.1"
authors = [
{ name="Mark Wolfman", email="[email protected]" },
]
Expand Down
21 changes: 13 additions & 8 deletions src/ophydregistry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/ophydregistry/tests/test_instrument_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 64b3a30

Please sign in to comment.