8000 [3.12] gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289) by miss-islington · Pull Request #109291 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] gh-109195: fix source location for super load before LOAD_SUPER_ATTR (GH-109289) #109291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,13 @@ def test_column_offset_deduplication(self):
list(code.co_consts[1].co_positions()),
)

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


class TestExpressionStackSize(unittest.TestCase):
# These tests check that the computed stack size for a code object
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix source location for the ``LOAD_*`` instruction preceding a
``LOAD_SUPER_ATTR`` to load the ``super`` global (or shadowing variable) so
that it encompasses only the name ``super`` and not the following
parentheses.
2 changes: 1 addition & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4776,7 +4776,7 @@ load_args_for_super(struct compiler *c, expr_ty e) {

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

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