MCPcopy Create free account
hub / github.com/python/cpython / test_negative_locations_for_compile

Method test_negative_locations_for_compile

Lib/test/test_ast/test_ast.py:204–222  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

202 compile(tree, "<string>", "exec")
203
204 def test_negative_locations_for_compile(self):
205 # See https://github.com/python/cpython/issues/130775
206 alias = ast.alias(name='traceback', lineno=0, col_offset=0)
207 for attrs in (
208 {'lineno': -2, 'col_offset': 0},
209 {'lineno': 0, 'col_offset': -2},
210 {'lineno': 0, 'col_offset': -2, 'end_col_offset': -2},
211 {'lineno': -2, 'end_lineno': -2, 'col_offset': 0},
212 ):
213 with self.subTest(attrs=attrs):
214 tree = ast.Module(body=[
215 ast.Import(names=[alias], **attrs)
216 ], type_ignores=[])
217
218 # It used to crash on this step:
219 compile(tree, "<string>", "exec")
220
221 # This also must not crash:
222 ast.parse(tree, optimize=2)
223
224 def test_docstring_optimization_single_node(self):
225 # https://github.com/python/cpython/issues/137308

Callers

nothing calls this directly

Calls 3

compileFunction · 0.50
subTestMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected