Remove escaping when converting EasyBuildError to a string#5009
Remove escaping when converting EasyBuildError to a string#5009boegel merged 5 commits intoeasybuilders:developfrom
EasyBuildError to a string#5009Conversation
Some exception texts have formatting such as quotes, newlines, tabs. Those should be preserved when reporting the error.
This ensures that formatting is kept
This reverts commit e83556b.
This ensures any formatting like newlines is kept.
d9dd161 to
8be2c5d
Compare
|
|
||
| def __str__(self): | ||
| """Return string representation of this EasyBuildError instance.""" | ||
| return repr(self.msg) |
There was a problem hiding this comment.
Hmm, there must have been a reason why we did this...
There was a problem hiding this comment.
C&P from some other code I'd say as this was introduced by renaming some other exception class in the very beginning: https://github.com/easybuilders/easybuild-framework/blame/d7f1ad2f6f09e387e121c94c9df434a07e7aaa68/easybuild/tools/buildLog.py
There is a __repr__ special method that should likely be implemented like that.
Someone notes at https://stackoverflow.com/questions/1436703/what-is-the-difference-between-str-and-repr
default for
__repr__which would act like:
return "%s(%r)" % (self.__class__, self.__dict__)
__repr__goal is to be unambiguous
__str__goal is to be readable
This means, in simple terms: almost every object you implement should have a functional__repr__that’s usable for understanding the object. Implementing__str__is optional: do that if you need a “pretty print” functionality (for example, used by a report generator).
SummaryImplement
__repr__for any class you implement. This should be second nature. Implement__str__if you think it would be useful to have a string version which errs on the side of readability.
E.g.
def __repr__(self):
return f'EasyBuildError({self.msg!r}, {self.exit_code})'
EasyBuildError to a string
This is especially useful for Pytorch tests where the error message contains formatted output which becomes hard to read: