mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.10] GH-95921: Fix positions for some chained comparisons (GH-96968) (GH-96974)
(cherry picked from commit dfc73b5724)
Automerge-Triggered-By: GH:brandtbucher
This commit is contained in:
parent
21b5af9072
commit
aced809dc4
6 changed files with 1671 additions and 1637 deletions
|
|
@ -984,6 +984,38 @@ def if_else_break():
|
|||
elif instr.opname in HANDLED_JUMPS:
|
||||
self.assertNotEqual(instr.arg, (line + 1)*INSTR_SIZE)
|
||||
|
||||
def test_compare_positions(self):
|
||||
for opname, op in [
|
||||
("COMPARE_OP", "<"),
|
||||
("COMPARE_OP", "<="),
|
||||
("COMPARE_OP", ">"),
|
||||
("COMPARE_OP", ">="),
|
||||
("CONTAINS_OP", "in"),
|
||||
("CONTAINS_OP", "not in"),
|
||||
("IS_OP", "is"),
|
||||
("IS_OP", "is not"),
|
||||
]:
|
||||
expr = f'a {op} b {op} c'
|
||||
expected_lines = 2 * [2]
|
||||
for source in [
|
||||
f"\\\n{expr}", f'if \\\n{expr}: x', f"x if \\\n{expr} else y"
|
||||
]:
|
||||
code = compile(source, "<test>", "exec")
|
||||
all_lines = (
|
||||
line
|
||||
for start, stop, line in code.co_lines()
|
||||
for _ in range(start, stop, 2)
|
||||
)
|
||||
actual_lines = [
|
||||
line
|
||||
for instruction, line in zip(
|
||||
dis.get_instructions(code), all_lines, strict=True
|
||||
)
|
||||
if instruction.opname == opname
|
||||
]
|
||||
with self.subTest(source):
|
||||
self.assertEqual(actual_lines, expected_lines)
|
||||
|
||||
|
||||
class TestExpressionStackSize(unittest.TestCase):
|
||||
# These tests check that the computed stack size for a code object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue