mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.12] gh-130775: Allow negative locations in ast (GH-130795) (#132260)
(cherry picked from commit bc5233b6a5)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
40f81e1060
commit
492a554cfc
3 changed files with 20 additions and 4 deletions
|
|
@ -160,6 +160,23 @@ class AST_Tests(unittest.TestCase):
|
|||
# Check that compilation doesn't crash. Note: this may crash explicitly only on debug mode.
|
||||
compile(tree, "<string>", "exec")
|
||||
|
||||
def test_negative_locations_for_compile(self):
|
||||
# See https://github.com/python/cpython/issues/130775
|
||||
alias = ast.alias(name='traceback', lineno=0, col_offset=0)
|
||||
for attrs in (
|
||||
{'lineno': -2, 'col_offset': 0},
|
||||
{'lineno': 0, 'col_offset': -2},
|
||||
{'lineno': 0, 'col_offset': -2, 'end_col_offset': -2},
|
||||
{'lineno': -2, 'end_lineno': -2, 'col_offset': 0},
|
||||
):
|
||||
with self.subTest(attrs=attrs):
|
||||
tree = ast.Module(body=[
|
||||
ast.Import(names=[alias], **attrs)
|
||||
], type_ignores=[])
|
||||
|
||||
# It used to crash on this step:
|
||||
compile(tree, "<string>", "exec")
|
||||
|
||||
def test_slice(self):
|
||||
slc = ast.parse("x[::]").body[0].value.slice
|
||||
self.assertIsNone(slc.upper)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue