[New-bugs-announce] [issue46389] 3.11: unused generator comprehensions cause f_lineno==None

Ned Batchelder report at bugs.python.org
Sat Jan 15 07:26:22 EST 2022


New submission from Ned Batchelder <ned at nedbatchelder.com>:

In Python 3.11, unused generator comprehensions cause trace events with f_lineno set to None.

---- %< -------------------------------------------------
import linecache, sys

def trace(frame, event, arg):
    # The weird globals here is to avoid a NameError on shutdown...
    if frame.f_code.co_filename == globals().get("__file__"):
        lineno = frame.f_lineno
        if lineno is not None:
            line = linecache.getline(__file__, lineno).rstrip()
        else:
            line = "<none>"
        print("{} {!s:4}: {}".format(event[:4], lineno, line))
    return trace

print(sys.version)
sys.settrace(trace)

(i for i in [1])
------------------------------------------------------

$ python3.10 /tmp/runbpo.py
3.10.2 (main, Jan 15 2022, 05:51:59) [Clang 12.0.0 (clang-1200.0.32.29)]
call 17  : (i for i in [1])
exce 17  : (i for i in [1])
retu 17  : (i for i in [1])

$ python3.11 /tmp/runbpo.py
3.11.0a4 (main, Jan 14 2022, 18:14:29) [Clang 12.0.0 (clang-1200.0.32.29)]
call None: <none>
exce None: <none>
retu None: <none>

----------
components: Interpreter Core
keywords: 3.11regression
messages: 410643
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: 3.11: unused generator comprehensions cause f_lineno==None
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46389>
_______________________________________


More information about the New-bugs-announce mailing list