Skip to content
Draft
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
16 changes: 8 additions & 8 deletions pyaml/bpm/bpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def __init__(
tilt: str | None = None,
):
super().__init__(name, lattice_names, description)
self._x_pos = x_pos
self._y_pos = y_pos
self._x_offset = x_offset
self._y_offset = y_offset
self._tilt_name = tilt
self.x_pos = x_pos
self.y_pos = y_pos
self.x_offset = x_offset
self.y_offset = y_offset
self.tilt_name = tilt
self._positions = None
self._offset = None
self._tilt = None
Expand Down Expand Up @@ -160,7 +160,7 @@ def get_pos_devices(self) -> list[str | None]:
list[DeviceAccess]
Array of DeviceAcess
"""
return [self._x_pos, self._y_pos]
return [self.x_pos, self.y_pos]

def get_tilt_device(self) -> str | None:
"""
Expand All @@ -171,7 +171,7 @@ def get_tilt_device(self) -> str | None:
DeviceAccess
DeviceAcess
"""
return self._tilt_name
return self.tilt_name

def get_offset_devices(self) -> list[str | None]:
"""
Expand All @@ -182,7 +182,7 @@ def get_offset_devices(self) -> list[str | None]:
list[DeviceAccess]
Array of DeviceAcess
"""
return [self._x_offset, self._y_offset]
return [self.x_offset, self.y_offset]

def __repr__(self):
return __pyaml_repr__(self, exclude=["positions", "offset", "tilt"])
51 changes: 27 additions & 24 deletions pyaml/common/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@

def __pyaml_repr__(obj, exclude: list[str] | None = None):
"""
Returns a string representation of a pyaml object.

Parameters
----------
exclude : list[str] | None
Attribute/property names to exclude from the output.
Returns a string representation of a pyaml object,
including inherited properties and one level of nested objects.
"""

if exclude is None:
exclude = []

Expand All @@ -34,31 +29,39 @@ def __pyaml_repr__(obj, exclude: list[str] | None = None):
)
return repr(cfg).replace("ConfigModel", cls_name, 1)

# Generic fallback when there is no _cfg
attrs = {}

# Instance attributes
for k, v in obj.__dict__.items():
# Exclude private attributes and excluded
if not k.startswith("_") and k not in exclude:
attrs[k] = v
for name in dir(obj):
# Skip private attributes and user-excluded names
if name.startswith("_") or name in exclude:
continue

try:
value = getattr(obj, name)

# Skip methods/functions (we only want data)
# This prevents: BPM(get_name=<bound method...>)
if callable(value):
continue

# Properties
for name, attr in vars(type(obj)).items():
if isinstance(attr, property) and name not in exclude:
try:
attrs[name] = getattr(obj, name)
except Exception as e:
attrs[name] = f"<error: {e}>"
attrs[name] = value
except Exception as e:
attrs[name] = f"<error: {e}>"

# Special handling for 'name' if it's an Element but not in attrs
if isinstance(obj, Element) and "name" not in attrs and "name" not in exclude:
try:
attrs["name"] = obj.get_name()
except Exception as e:
attrs["name"] = f"<error: {e}>"
except Exception:
pass

# The !r flag ensures that if 'v' is another pyaml object,
# its own __repr__ is called (providing the "one level below" effect).
if not attrs:
return cls_name

parts = ", ".join(f"{k}={v!r}" for k, v in attrs.items())
return f"{cls_name}({parts})" if parts else cls_name
parts = ", ".join(f"{k}={v!r}" for k, v in sorted(attrs.items()))
return f"{cls_name}({parts})"


class ElementConfigModel(BaseModel):
Expand Down
Loading