-
Notifications
You must be signed in to change notification settings - Fork 216
Remove escaping when converting EasyBuildError to a string #5009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, there must have been a reason why we did this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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})'
This is especially useful for Pytorch tests where the error message contains formatted output which becomes hard to read: