| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -622,10 +622,14 @@ class TracebackException: | |
| occurred. | ||
| - :attr:`lineno` For syntax errors - the linenumber where the error | ||
| occurred. | ||
| - :attr:`end_lineno` For syntax errors - the end linenumber where the error | ||
| occurred. Can be `None` if not present. | ||
| - :attr:`text` For syntax errors - the text where the error | ||
| occurred. | ||
| - :attr:`offset` For syntax errors - the offset into the text where the | ||
| error occurred. | ||
| - :attr:`end_offset` For syntax errors - the offset into the text where the | ||
| error occurred. Can be `None` if not present. | ||
| - :attr:`msg` For syntax errors - the compiler error message. | ||
| """ | ||
|
|
||
| Expand Down Expand Up | @@ -655,8 +659,11 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None, | |
| self.filename = exc_value.filename | ||
| lno = exc_value.lineno | ||
| self.lineno = str(lno) if lno is not None else None | ||
| end_lno = exc_value.end_lineno | ||
| self.end_lineno = str(end_lno) if end_lno is not None else None | ||
| self.text = exc_value.text | ||
| self.offset = exc_value.offset | ||
| self.end_offset = exc_value.end_offset | ||
| self.msg = exc_value.msg | ||
| if lookup_lines: | ||
| self._load_lines() | ||
| Expand Down Expand Up | @@ -771,12 +778,20 @@ def _format_syntax_error(self, stype): | |
| ltext = rtext.lstrip(' \n\f') | ||
| spaces = len(rtext) - len(ltext) | ||
| yield ' {}\n'.format(ltext) | ||
| # Convert 1-based column offset to 0-based index into stripped text | ||
| caret = (self.offset or 0) - 1 - spaces | ||
| if caret >= 0: | ||
| # non-space whitespace (likes tabs) must be kept for alignment | ||
| caretspace = ((c if c.isspace() else ' ') for c in ltext[:caret]) | ||
| yield ' {}^\n'.format(''.join(caretspace)) | ||
|
|
||
| if self.offset is not None: | ||
| offset = self.offset | ||
| end_offset = self.end_offset if self.end_offset is not None else offset | ||
| if offset == end_offset or end_offset == -1: | ||
| end_offset = offset + 1 | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI've noticed that self.end_offset is 0 with https://bugs.python.org/msg403588 (https://bugs.python.org/issue45249).
Sorry, something went wrong.
pablogsal reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAddressed in #28855
Sorry, something went wrong.
All reactions
|
||
|
|
||
| # Convert 1-based column offset to 0-based index into stripped text | ||
| colno = offset - 1 - spaces | ||
| end_colno = end_offset - 1 - spaces | ||
| if colno >= 0: | ||
| # non-space whitespace (likes tabs) must be kept for alignment | ||
| caretspace = ((c if c.isspace() else ' ') for c in ltext[:colno]) | ||
| yield ' {}{}'.format("".join(caretspace), ('^' * (end_colno - colno) + "\n")) | ||
| msg = self.msg or "<no detail available>" | ||
| yield "{}: {}{}\n".format(stype, msg, filename_suffix) | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt is not None, but an unset attribute for non-SyntaxErrors, since it gets set for if exc_type and issubclass(exc_type, SyntaxError) only.
I think it should either get initialized always (to None), or at least the doc should get fixed (both places above).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI disagree. The text is the same as for other syntax errors fields. It says:
the same way offset is also for syntax errors:
The thing here is that end_offset can be None if not present even for syntax errors.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.