Skip to content

Commit

Permalink
🧑‍💻 Add __repr__ method to Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Jul 13, 2024
1 parent 02d1a14 commit 1b11462
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CPAC/pipeline/engine/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ def __getitem__(self, name: str) -> tuple[pe.Node, str | tuple[str]]:
msg = f"Key '{name}' not set in {self}."
raise KeyError(msg)

def __repr__(self) -> str:
"""Return reproducible string for Resource."""
positional = f"Resource(data={self.data}, json={self.json}"
kw = ", ".join(
f"{key}={getattr(self, key)}"
for key in self.keys()
if key not in ["data", "json"]
)
return f"{positional}{kw})"

def __setitem__(self, name: str, value: Any) -> None:
"""Provide legacy dict-style set access."""
setattr(self, name, value)
Expand Down

0 comments on commit 1b11462

Please sign in to comment.