New submission from Ned Batchelder <n...@nedbatchelder.com>:

Note: this is very similar to https://bugs.python.org/issue42810
This was originally reported against coverage.py: 
https://github.com/nedbat/coveragepy/issues/1205

---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

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

def func():
    if A:
        if B:
            if C:
                if D:
                    return False
        else:
            return False
    elif E and F:
        return True

A = B = True
C = False

func()
-------------------------

This produces this trace output:

3.10.0rc1 (default, Aug  3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
call 13: def func():
line 14:     if A:
line 15:         if B:
line 16:             if C:
line 21:     elif E and F:
retu 21:     elif E and F:

The elif on line 21 is not executed, and should not be traced.

Also, if I change line 21 to `elif E:`, then the trace changes to:

3.10.0rc1 (default, Aug  3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
call 13: def func():
line 14:     if A:
line 15:         if B:
line 16:             if C:
line 22:         return True
retu 22:         return True

----------
components: Interpreter Core
keywords: 3.10regression
messages: 399003
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: Nested if/else gets phantom else trace again (3.10)
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44840>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to