This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nedbat
Recipients Mark.Shannon, nedbat
Date 2022-01-09.14:40:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1641739204.02.0.251186748791.issue46314@roundup.psfhosted.org>
In-reply-to
Content
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@15   (first=15): def f():
retu bug233.py@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@15   (first=15): def f():
call bug233.py@17   (first=15):     fn = lambda: 2
retu bug233.py@18   (first=15):     b = 3
History
Date User Action Args
2022-01-09 14:40:04nedbatsetrecipients: + nedbat, Mark.Shannon
2022-01-09 14:40:04nedbatsetmessageid: <1641739204.02.0.251186748791.issue46314@roundup.psfhosted.org>
2022-01-09 14:40:03nedbatlinkissue46314 messages
2022-01-09 14:40:03nedbatcreate