Skip to content

Commit

Permalink
rf(CommandError): discontinue to_str() method
Browse files Browse the repository at this point in the history
In a previous implementation this method used to have parameters, but
presently it does not. Nevertheless it represented a public API
components without a real purpose. it was removed and the same
functionality continues to be available via the standard `__str__()`
method.
  • Loading branch information
mih committed Jun 7, 2024
1 parent e5a3c15 commit a793a47
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions datasalad/runners/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self.stderr = stderr
self.cwd = cwd

def to_str(self) -> str:
def __str__(self) -> str:
# we report the command verbatim, in exactly the form that it has
# been given to the exception. Previously implementation have
# beautified output by joining list-format commands with shell
Expand All @@ -67,12 +67,8 @@ def to_str(self) -> str:
# but we support it, because CommandError derives
# from RuntimeError which has this feature.
to_str += f" [{self.msg}]"

return to_str

def __str__(self) -> str:
return self.to_str()

def __repr__(self) -> str:
descr = f"{self.__class__.__name__}({self.cmd!r}"
for kwarg, (val, default) in dict(
Expand Down
2 changes: 1 addition & 1 deletion datasalad/runners/tests/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def test_CommandError_str_repr() -> None:
"CommandError('mycmd', returncode=-6)")
)
for ce, _str, _repr in testcases:
assert ce.to_str() == str(ce) == _str
assert str(ce) == _str
assert repr(ce) == _repr

0 comments on commit a793a47

Please sign in to comment.