Skip to content
Snippets Groups Projects
Commit c3b084e7 authored by Lamm, Sascha's avatar Lamm, Sascha :cow2:
Browse files

fixed a compatibility issue with the LegoAssembly and LegoComponent classes...

fixed a compatibility issue with the LegoAssembly and LegoComponent classes when using Python 3.11. Updated both __repr__ dunder methods to be more verbose
parent 13e908e3
No related branches found
No related tags found
No related merge requests found
......@@ -191,7 +191,18 @@ class LegoComponent:
str: A string representing the LegoComponent instance.
"""
return f"LegoComponent({self.properties if self.properties else ""})"
label_str = ""
if self.properties["label"] is not None:
label_str = f"label='{self.properties['label']}', "
property_str = ", ".join(
[
f"'{k}': '{v}'" if isinstance(v, str) else f"'{k}': {v}"
for k, v in self.properties.items()
if not k == "label"
]
)
property_str = f"**{{{property_str}}}" if property_str else property_str
return f"LegoComponent({label_str}{property_str})"
def __str__(self):
"""Handle the conversion of LegoComponent objects to str objects.
......@@ -519,9 +530,35 @@ class LegoAssembly:
return False
def __repr__(self):
"""Create a machine-readable representation of the instance.
Returns:
str: A string representing the LegoAssembly instance.
"""
label_str = ""
if self.properties["label"] is not None:
label_str = f"label='{self.properties['label']}', "
layer_str = f"layer={self._layer}, "
property_str = ", ".join(
[
f"'{k}': '{v}'" if isinstance(v, str) else f"'{k}': {v}"
for k, v in self.properties.items()
if not k == "label"
]
)
property_str = f"**{{{property_str}}}" if property_str else property_str
return f"LegoAssembly({label_str}{layer_str}{property_str})"
def __str__(self):
"""Handle the conversion of LegoComponent objects to str objects.
Returns:
str: A string converted from the LegoComponent instance.
"""
String representation of the object including the component label and UUID.
"""
if self.properties["label"] is None:
return f"LegoAssembly [{self._uuid}]"
return f"LegoAssembly {self.properties['label']} [{self._uuid}]"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment