Skip to content

Commit 2004e12

Browse files
[3.12] gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289) (#109291)
gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289) (cherry picked from commit ceeb417) Co-authored-by: Carl Meyer <carl@oddbird.net>
1 parent 8e96b98 commit 2004e12

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/test/test_compile.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,13 @@ def test_column_offset_deduplication(self):
17421742
list(code.co_consts[1].co_positions()),
17431743
)
17441744

1745+
def test_load_super_attr(self):
1746+
source = "class C:\n def __init__(self):\n super().__init__()"
1747+
code = compile(source, "<test>", "exec").co_consts[0].co_consts[1]
1748+
self.assertOpcodeSourcePositionIs(
1749+
code, "LOAD_GLOBAL", line=3, end_line=3, column=4, end_column=9
1750+
)
1751+
17451752

17461753
class TestExpressionStackSize(unittest.TestCase):
17471754
# These tests check that the computed stack size for a code object
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix source location for the ``LOAD_*`` instruction preceding a
2+
``LOAD_SUPER_ATTR`` to load the ``super`` global (or shadowing variable) so
3+
that it encompasses only the name ``super`` and not the following
4+
parentheses.

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4776,7 +4776,7 @@ load_args_for_super(struct compiler *c, expr_ty e) {
47764776

47774777
// load super() global
47784778
PyObject *super_name = e->v.Call.func->v.Name.id;
4779-
RETURN_IF_ERROR(compiler_nameop(c, loc, super_name, Load));
4779+
RETURN_IF_ERROR(compiler_nameop(c, LOC(e->v.Call.func), super_name, Load));
47804780

47814781
if (asdl_seq_LEN(e->v.Call.args) == 2) {
47824782
VISIT(c, expr, asdl_seq_GET(e->v.Call.args, 0));

0 commit comments

Comments
 (0)