Skip to content

bpo-45249: Ensure the traceback module prints correctly syntax errors with ranges #28575

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

Merged
merged 1 commit into from
Sep 27, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Sep 26, 2021

@pablogsal pablogsal merged commit 20f439b into python:main Sep 27, 2021
@pablogsal pablogsal deleted the bpo-45249 branch September 27, 2021 20:59
@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-28587 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Sep 27, 2021
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 27, 2021
… with ranges (pythonGH-28575)

(cherry picked from commit 20f439b)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
miss-islington added a commit that referenced this pull request Sep 27, 2021
… with ranges (GH-28575)

(cherry picked from commit 20f439b)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
pablogsal added a commit that referenced this pull request Sep 29, 2021
… with ranges (GH-28575)

(cherry picked from commit 20f439b)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
- :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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It 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).

Copy link
Member Author

@pablogsal pablogsal Oct 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should either get initialized always (to None), or at least the doc should get fixed (both places above).

I disagree. The text is the same as for other syntax errors fields. It says:

attr:end_offset For syntax errors

the same way offset is also for syntax errors:

:attr:offset For syntax errors

The thing here is that end_offset can be None if not present even for syntax errors.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that self.end_offset is 0 with https://bugs.python.org/msg403588 (https://bugs.python.org/issue45249).
This might boil down to / coming from the C code using -1 for "not given/used", and then 1 being added, and therefore 0 should also get handled as "no end offset provided, use a length of 1".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #28855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants