Skip to content

Commit

Permalink
Fix match statements
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed May 17, 2024
1 parent f19d41c commit 77a5f47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions src/rod/pretty_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,27 @@ def dataclass_to_str(obj: Any, level: int = 1) -> str:
for field in dataclasses.fields(obj):
attr = getattr(obj, field.name)

if attr is None or attr == "":
continue

elif isinstance(attr, list):
list_str = DataclassPrettyPrinter.list_to_string(
obj=attr, level=level + 1
)
serialization += [(field.name, list_str)]
continue

elif dataclasses.is_dataclass(attr):
dataclass_str = DataclassPrettyPrinter.dataclass_to_str(
obj=attr, level=level + 1
)
serialization += [(field.name, dataclass_str)]
continue

else:
serialization += [(field.name, f"{attr!s}")]
continue
match attr:
case None | "":
continue

case list():
list_str = DataclassPrettyPrinter.list_to_string(
obj=attr, level=level + 1
)
serialization += [(field.name, list_str)]
continue

case _ if dataclasses.is_dataclass(attr):
dataclass_str = DataclassPrettyPrinter.dataclass_to_str(
obj=attr, level=level + 1
)
serialization += [(field.name, dataclass_str)]
continue

case _:
serialization += [(field.name, f"{attr!s}")]
continue

spacing = " " * 4
spacing_level = spacing * level
Expand Down
2 changes: 1 addition & 1 deletion src/rod/utils/frame_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def find_parent_link_of_frame(frame: rod.Frame, model: rod.Model) -> str:
case anchor if anchor in frames_dict:
parent = frames_dict[frame.attached_to]

case frame if frame.attached in {model.name, "__model__"}:
case anchor if anchor in {model.name, "__model__"}:
return model.get_canonical_link()

case anchor if anchor in joints_dict:
Expand Down

0 comments on commit 77a5f47

Please sign in to comment.