From 2004e12d8d6268795425a57b4f5b4fb7e895d1ea Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 12 Sep 2023 07:20:41 -0700 Subject: [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 ceeb4173aee7b835f553a8286feaa48b98c16124) Co-authored-by: Carl Meyer --- Lib/test/test_compile.py | 7 +++++++ .../2023-09-11-15-51-55.gh-issue-109195.iwxmuo.rst | 4 ++++ Python/compile.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-09-11-15-51-55.gh-issue-109195.iwxmuo.rst diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 19b5aeb..16a59c1 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1742,6 +1742,13 @@ class TestSourcePositions(unittest.TestCase): 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, "", "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 diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-09-11-15-51-55.gh-issue-109195.iwxmuo.rst b/Misc/NEWS.d/next/Core and Builtins/2023-09-11-15-51-55.gh-issue-109195.iwxmuo.rst new file mode 100644 index 0000000..5427232 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-09-11-15-51-55.gh-issue-109195.iwxmuo.rst @@ -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. diff --git a/Python/compile.c b/Python/compile.c index 9395f52..b6e5adf 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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)); -- cgit v0.12