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

* `end_offset` is ignored in subclasses of SyntaxError

* 📜🤖 Added by blurb_it.

* Add test

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
Nice Zombies 2024-12-11 10:09:34 +01:00 committed by GitHub
parent 20c0c8cf38
commit 487a51a1b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 34 deletions

View file

@ -2195,6 +2195,22 @@ class SyntaxErrorTests(unittest.TestCase):
self.assertIn(expected, err.getvalue())
the_exception = exc
def test_subclass(self):
class MySyntaxError(SyntaxError):
pass
try:
raise MySyntaxError("bad bad", ("bad.py", 1, 2, "abcdefg", 1, 7))
except SyntaxError as exc:
with support.captured_stderr() as err:
sys.__excepthook__(*sys.exc_info())
self.assertIn("""
File "bad.py", line 1
abcdefg
^^^^^
""", err.getvalue())
def test_encodings(self):
self.addCleanup(unlink, TESTFN)
source = (