Skip to content

[3.12] gh-111609: end_offset is ignored in subclasses of SyntaxError #127554

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 3 commits into from
Dec 11, 2024

Conversation

nineteendo
Copy link
Contributor

@nineteendo nineteendo commented Dec 3, 2024

Example:

class CustomSyntaxError(SyntaxError):
    pass

raise CustomSyntaxError("Error message", (None, 1, 5, 'a = sin(3)', 1, 9))

main:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    a = sin(3)
        ^
CustomSyntaxError: Error message

PR:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    a = sin(3)
        ^^^^
CustomSyntaxError: Error message

@nineteendo nineteendo marked this pull request as ready for review December 3, 2024 12:41
@nineteendo
Copy link
Contributor Author

nineteendo commented Dec 3, 2024

@pablogsal, do you remember why this check was added in #25525? This works fine:

>>> class CustomSyntaxError(SyntaxError):
...     def __init__(self, msg, filename, lineno, offset, text, end_lineno, end_offset):
...         self.msg = msg
...         self.filename = filename
...         self.lineno = lineno
...         self.offset = offset
...         self.text = text
...         # self.end_lineno = end_lineno
...         # self.end_offset = end_offset
... 
>>> raise CustomSyntaxError("Error message", None, 1, 5, 'a = sin(3)', 1, 9)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    a = sin(3)
        ^
CustomSyntaxError: Error message

@pablogsal
Copy link
Member

pablogsal commented Dec 11, 2024

do you remember why this check was added in

What check are you referring to? The subclass check? IIRC is because some people were using some subclasses of syntax errors that were yielding weird results when displayed but I searched for the conversation and could not find anything :S

@@ -2195,6 +2195,22 @@ def test_range_of_offsets(self):
self.assertIn(expected, err.getvalue())
the_exception = exc

def test_subclass(self):
Copy link
Member

Choose a reason for hiding this comment

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

Can we also add this test to main if is not there already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a PR: #127830

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for the catch @nineteendo!

@pablogsal pablogsal enabled auto-merge (squash) December 11, 2024 09:09
@pablogsal pablogsal merged commit 487a51a into python:3.12 Dec 11, 2024
32 checks passed
@nineteendo nineteendo deleted the syntaxerr-subclass branch December 11, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants