Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions bec_lib/bec_lib/devicemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ def __contains__(self, key: object) -> bool:
return super().__contains__(key)

def __getattr__(self, attr):
if attr.startswith("_"):
# if dunder attributes are would not be caught, they
# would raise a DeviceConfigError and kill the
# IPython completer
# pylint: disable=no-member
return super().__getattr__(attr)
if attr.startswith("__"):
# Keep missing dunder lookups as AttributeError so
# introspection and IPython completion can probe safely.
raise AttributeError(f"{type(self).__name__!r} object has no attribute {attr!r}")
Comment thread
wakonig marked this conversation as resolved.
dev = self.get(attr)
if not dev:
raise DeviceConfigError(f"Device {attr} does not exist.")
Expand Down
5 changes: 5 additions & 0 deletions bec_lib/tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ def test_device_container_wm_raises_for_missing_device(dev_container):
dev_container.wm("missing")


def test_device_container_getattr_raises_for_missing_single_underscore_device(dev_container):
with pytest.raises(DeviceConfigError, match="Device _something does not exist\\."):
dev_container._something

Comment thread
wakonig marked this conversation as resolved.

def test_device_container_wm_raises_for_unmatched_glob(dev_container):
with pytest.raises(DeviceConfigError, match="No devices match pattern miss\\*\\."):
dev_container.wm("miss*")
Expand Down
Loading