mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
[3.12] gh-123048: Fix missing source location in pattern matching code (GH-123167) (#123170)
gh-123048: Fix missing source location in pattern matching code (GH-123167)
(cherry picked from commit bffed80230
)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
747abc00d0
commit
919a3e8028
2 changed files with 21 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
import array
|
import array
|
||||||
import collections
|
import collections
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import dis
|
||||||
import enum
|
import enum
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
@ -3083,6 +3084,24 @@ class TestValueErrors(unittest.TestCase):
|
||||||
self.assertIs(y, None)
|
self.assertIs(y, None)
|
||||||
self.assertIs(z, None)
|
self.assertIs(z, None)
|
||||||
|
|
||||||
|
class TestSourceLocations(unittest.TestCase):
|
||||||
|
def test_jump_threading(self):
|
||||||
|
# See gh-123048
|
||||||
|
def f():
|
||||||
|
x = 0
|
||||||
|
v = 1
|
||||||
|
match v:
|
||||||
|
case 1:
|
||||||
|
if x < 0:
|
||||||
|
x = 1
|
||||||
|
case 2:
|
||||||
|
if x < 0:
|
||||||
|
x = 1
|
||||||
|
x += 1
|
||||||
|
|
||||||
|
for inst in dis.get_instructions(f):
|
||||||
|
if inst.opcode in dis.hasjrel or inst.opcode in dis.hasjabs:
|
||||||
|
self.assertIsNotNone(inst.positions.lineno, "jump without location")
|
||||||
|
|
||||||
class TestTracing(unittest.TestCase):
|
class TestTracing(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a bug where pattern matching code could emit a :opcode:`JUMP_FORWARD`
|
||||||
|
with no source location.
|
Loading…
Add table
Add a link
Reference in a new issue