8000 gh-109195: fix source location for super load before LOAD_SUPER_ATTR … · python/cpython@ceeb417 · GitHub
[go: up one dir, main page]

Skip to content

Commit ceeb417

Browse files
authored
gh-109195: fix source location for super load before LOAD_SUPER_ATTR (#109289)
1 parent fbaf77e commit ceeb417

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
@@ -1751,6 +1751,13 @@ def test_column_offset_deduplication(self):
17511751
list(code.co_consts[1].co_positions()),
17521752
)
17531753

1754+
def test_load_super_attr(self):
1755+
source = "class C:\n def __init__(self):\n super().__init__()"
1756+
code = compile(source, "<test>", "exec").co_consts[0].co_consts[1]
1757+
self.assertOpcodeSourcePositionIs(
1758+
code, "LOAD_GLOBAL", line=3, end_line=3, column=4, end_column=9
1759+
)
1760+
17541761

17551762
class TestExpressionStackSize(unittest.TestCase):
17561763
# 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
@@ -4868,7 +4868,7 @@ load_args_for_super(struct compiler *c, expr_ty e) {
48684868

48694869
// load super() global
48704870
PyObject *super_name = e->v.Call.func->v.Name.id;
4871-
RETURN_IF_ERROR(compiler_nameop(c, loc, super_name, Load));
4871+
RETURN_IF_ERROR(compiler_nameop(c, LOC(e->v.Call.func), super_name, Load));
48724872

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

0 commit comments

Comments
 (0)
0