8000 Trace reports wrong executed line inside case block · Issue #105163 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Trace reports wrong executed line inside case block #105163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DavideCanton opened this issue May 31, 2023 · 3 comments
Closed

Trace reports wrong executed line inside case block #105163

DavideCanton opened this issue May 31, 2023 · 3 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@DavideCanton
Copy link

Bug report

When executing a script that has an if inside a case block, if the condition in the if block is false, the trace module reports that the last line of the if block is executed, even it is false.

This causes problems with debuggers and code coverage tools.

An example of the problem:

# script bug.py

def foo(n, m):
    match n:
        case 1:
            if m > 0:
                return 1 / 0     
    return -42

foo(1, -1)

The output is:

$ python -m trace -t bug.py
 --- modulename: bug, funcname: <module>
bug.py(3): def foo(n, m):
bug.py(10): foo(1, -1)
 --- modulename: bug, funcname: foo
bug.py(4):     match n:
bug.py(5):         case 1:
bug.py(6):             if m > 0:
bug.py(7):                 return 1 / 0
bug.py(8):     return -42

I can't understand why the row 7 (the line with the return 1 / 0) is reported as executed in the trace.

The line is not executed, as the program doesn't raise a ZeroDivisionError.

I've tried searching in the issue tracker but didn't find anything, sorry if I missed some already existing issue.

Your environment

  • CPython versions tested on:
    • 3.10.9
    • 3.11.0
  • Operating system and architecture:
    • windows 64 bit
@DavideCanton DavideCanton added the type-bug An unexpected behavior, bug, or error label May 31, 2023
@brandtbucher
Copy link
Member

Might be a duplicate of #99474 and #103971.

@brandtbucher brandtbucher self-assigned this May 31, 2023
@brandtbucher
Copy link
Member
brandtbucher commented May 31, 2023

Thanks for the report! I've confirmed that this doesn't reproduce on a more recent 3.11.

3.11.4, which will include the fix, is scheduled to be released on Monday.

@brandtbucher brandtbucher closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
@DavideCanton
Copy link
Author

Thanks for the response 👍🏻 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants
0