[New-bugs-announce] [issue44450] Generator expressions trace differently on Windows than on Mac

Ned Batchelder report at bugs.python.org
Fri Jun 18 07:50:04 EDT 2021


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

Here is a trace involving generator expressions.  Using 3.10.0b3 on Mac, there are "line" events within the expression.  Those events are missing on Windows.

--- 8< -------------------------------
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
        print("{} {}: {}".format(event[:4], lineno, linecache.getline(__file__, lineno).rstrip()))
    return trace

def doit():
    o = ((1,2), (3,4))
    o = (a for a in o)
    for tup in o:
        x = tup[0]
        y = tup[1]

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

When run on Mac, it produces this output:


3.10.0b3 (default, Jun 18 2021, 06:43:38) [Clang 12.0.0 (clang-1200.0.32.29)]
call 10: def doit():
line 11:     o = ((1,2), (3,4))
line 12:     o = (a for a in o)
line 13:     for tup in o:
call 12:     o = (a for a in o)
line 12:     o = (a for a in o)
retu 12:     o = (a for a in o)
line 14:         x = tup[0]
line 15:         y = tup[1]
line 13:     for tup in o:
call 12:     o = (a for a in o)
line 12:     o = (a for a in o)
retu 12:     o = (a for a in o)
line 14:         x = tup[0]
line 15:         y = tup[1]
line 13:     for tup in o:
call 12:     o = (a for a in o)
retu 12:     o = (a for a in o)
retu 13:     for tup in o:


When run on Windows, it produces this output:

3.10.0b3 (tags/v3.10.0b3:865714a, Jun 17 2021, 20:39:25) [MSC v.1929 64 bit (AMD64)]
call 10: def doit():
line 11:     o = ((1,2), (3,4))
line 12:     o = (a for a in o)
line 13:     for tup in o:
call 12:     o = (a for a in o)
retu 12:     o = (a for a in o)
line 14:         x = tup[0]
line 15:         y = tup[1]
line 13:     for tup in o:
call 12:     o = (a for a in o)
retu 12:     o = (a for a in o)
line 14:         x = tup[0]
line 15:         y = tup[1]
line 13:     for tup in o:
call 12:     o = (a for a in o)
retu 12:     o = (a for a in o)
retu 13:     for tup in o:

On Windows, the "line 12" events are missing.

----------
components: Interpreter Core
keywords: 3.10regression
messages: 396050
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: Generator expressions trace differently on Windows than on Mac
versions: Python 3.10

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


More information about the New-bugs-announce mailing list