-
Notifications
You must be signed in to change notification settings - Fork 140
Improve string representation of Assert Ops #739
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,13 @@ def __init__(self, exc_type, msg=""): | |
self.msg = msg | ||
|
||
def __str__(self): | ||
return f"CheckAndRaise{{{self.exc_type}({self.msg})}}" | ||
name = self.__class__.__name__ | ||
exc_name = self.exc_type.__name__ | ||
if len(self.msg) > 30: | ||
msg = self.msg[:27] + "..." | ||
else: | ||
msg = self.msg | ||
Comment on lines
+53
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit conflicted here. Why do we want to contain the error message? I understand that it makes the code more readable but it would also hide some important information regarding the message. Although the length of 27 again seems sufficient when displaying the error message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just for the text representation (like when doing Right now showing the whole message makes graph printing pretty ugly. That's the whole point of this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh I see. LGTM 👍 |
||
return f"{name}{{raises={exc_name}, msg='{msg}'}}" | ||
|
||
def __eq__(self, other): | ||
if type(self) != type(other): | ||
|
@@ -195,7 +201,11 @@ def __init__(self, msg="PyTensor Assert failed!"): | |
super().__init__(AssertionError, msg) | ||
|
||
def __str__(self): | ||
return f"Assert{{msg={self.msg}}}" | ||
if len(self.msg) > 30: | ||
msg = self.msg[:27] + "..." | ||
else: | ||
msg = self.msg | ||
return f"Assert{{msg='{msg}'}}" | ||
|
||
|
||
assert_op = Assert() | ||
|
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.
Will the
name
variable not always be instance ofCheckAndRaise
in itself here? If so what is the benefit of having a separate variable for it?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.
If there is a subclass it will use the subclass name instead