[New-bugs-announce] [issue46314] Stray RESUME opcode for unused lambda
Ned Batchelder
report at bugs.python.org
Sun Jan 9 09:40:04 EST 2022
New submission from Ned Batchelder <ned at nedbatchelder.com>:
This code seems to get a RESUME opcode where no function call is happening:
a = 1
fn = lambda 2
b = 3
Here is the disassembly. Offset 6 has a RESUME opcode for line 2:
Python 3.11.0a3+ (heads/main:0fc58c1e05, Jan 8 2022, 19:45:58) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dis
>>> dis.dis("""\
... a = 1
... fn = lambda: 2
... b = 3
... """)
0 RESUME 0
1 2 LOAD_CONST 0 (1)
4 STORE_NAME 0 (a)
2 6 RESUME 0
8 LOAD_CONST 1 (<code object <lambda> at 0x10772c2d0, file "<dis>", line 2>)
10 MAKE_FUNCTION 0
12 STORE_NAME 1 (fn)
3 14 LOAD_CONST 2 (3)
16 STORE_NAME 2 (b)
18 LOAD_CONST 3 (None)
20 RETURN_VALUE
Disassembly of <code object <lambda> at 0x10772c2d0, file "<dis>", line 2>:
2 0 RESUME 0
2 LOAD_CONST 1 (2)
4 RETURN_VALUE
This causes an extra "call" event when tracing:
---< bug233.py >--------------------------------------------------------
import linecache, os.path, sys
def trace(frame, event, arg):
if (event != "line") and ("bug233" in frame.f_code.co_filename):
lineno = frame.f_lineno
first = frame.f_code.co_firstlineno
source = linecache.getline(frame.f_code.co_filename, lineno) if lineno else "******"
file = os.path.basename(frame.f_code.co_filename)
print("{} {}@{!s:4} (first={}): {}".format(event[:4], file, lineno, first, source.rstrip()))
return trace
print(sys.version)
sys.settrace(trace)
def f():
a = 1
fn = lambda: 2
b = 3
f()
------------------------------------------------------------------------
% python3.10 bug233.py
3.10.1 (main, Dec 14 2021, 08:30:13) [Clang 12.0.0 (clang-1200.0.32.29)]
call bug233.py at 15 (first=15): def f():
retu bug233.py at 18 (first=15): b = 3
% python3.11 bug233.py
3.11.0a3+ (heads/main:0fc58c1e05, Jan 8 2022, 19:45:58) [Clang 12.0.0 (clang-1200.0.32.29)]
call bug233.py at 15 (first=15): def f():
call bug233.py at 17 (first=15): fn = lambda: 2
retu bug233.py at 18 (first=15): b = 3
----------
components: Interpreter Core
keywords: 3.11regression
messages: 410151
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: Stray RESUME opcode for unused lambda
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46314>
_______________________________________
More information about the New-bugs-announce
mailing list