summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-19 13:22:21 (GMT)
committerGitHub <noreply@github.com>2024-06-19 13:22:21 (GMT)
commit4ce1246a9958d2d1452f83be961e369f7d050714 (patch)
treeec9fbbbf9dbc65cb1473c279f644670d32a4695c /Lib/test/test_compile.py
parentc598e61a223edcd9a7eecf823f667e2e810aba53 (diff)
downloadcpython-4ce1246a9958d2d1452f83be961e369f7d050714.zip
cpython-4ce1246a9958d2d1452f83be961e369f7d050714.tar.gz
cpython-4ce1246a9958d2d1452f83be961e369f7d050714.tar.bz2
[3.13] gh-120722: Set position on RETURN_VALUE in lambda (GH-120724) (#120738)
(cherry picked from commit d8f27cb1141fd3575de816438ed80a916c0560ed) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r--Lib/test/test_compile.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 6be6155..e29c95e 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -15,7 +15,7 @@ import warnings
import _testinternalcapi
from test import support
-from test.support import (script_helper, requires_debug_ranges,
+from test.support import (script_helper, requires_debug_ranges, run_code,
requires_specialization, get_c_recursion_limit)
from test.support.bytecode_helper import instructions_with_positions
from test.support.os_helper import FakePath
@@ -2028,6 +2028,33 @@ class TestSourcePositions(unittest.TestCase):
code, "LOAD_GLOBAL", line=3, end_line=3, column=4, end_column=9
)
+ def test_lambda_return_position(self):
+ snippets = [
+ "f = lambda: x",
+ "f = lambda: 42",
+ "f = lambda: 1 + 2",
+ "f = lambda: a + b",
+ ]
+ for snippet in snippets:
+ with self.subTest(snippet=snippet):
+ lamb = run_code(snippet)["f"]
+ positions = lamb.__code__.co_positions()
+ # assert that all positions are within the lambda
+ for i, pos in enumerate(positions):
+ with self.subTest(i=i, pos=pos):
+ start_line, end_line, start_col, end_col = pos
+ if i == 0 and start_col == end_col == 0:
+ # ignore the RESUME in the beginning
+ continue
+ self.assertEqual(start_line, 1)
+ self.assertEqual(end_line, 1)
+ code_start = snippet.find(":") + 2
+ code_end = len(snippet)
+ self.assertGreaterEqual(start_col, code_start)
+ self.assertLessEqual(end_col, code_end)
+ self.assertGreaterEqual(end_col, start_col)
+ self.assertLessEqual(end_col, code_end)
+
class TestExpectedAttributes(unittest.TestCase):