Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

3.12 tracing regression: a conditional in a finally block will revisit the condition before exiting the block. #105658

Closed
Assignees
iritkatriel
Labels
3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error
@nedbat

Description

@nedbat

Python 3.12 introduced a change in tracing behavior. Now a conditional in a finally block will revisit the condition before exiting the block.

Here is test.py:

importsysprint(sys.version)defexample(raise_exc:bool,enter_finally_cond:bool):try:ifraise_exc:print("raising exception")raiseExceptionprint("not raising exception")finally:ifenter_finally_cond:print("in finally conditional")print("after finally")try:example(raise_exc=True,enter_finally_cond=True)except:pass

When traced under 3.11:

% python3.11 -m trace --trace test.py --- modulename: test, funcname: <module>test.py(1): import systest.py(2): print(sys.version)3.11.4 (main, Jun  7 2023, 08:42:37) [Clang 14.0.3 (clang-1403.0.22.14.1)]test.py(4): def example(raise_exc: bool, enter_finally_cond: bool):test.py(16): try:test.py(17):     example(raise_exc=True, enter_finally_cond=True) --- modulename: test, funcname: exampletest.py(5):     try:test.py(6):         if raise_exc:test.py(7):             print("raising exception")raising exceptiontest.py(8):             raise Exceptiontest.py(11):         if enter_finally_cond:test.py(12):             print("in finally conditional")in finally conditionaltest.py(18): except:test.py(19):     pass

When traced under 3.12:

% python3.12 -m trace --trace test.py --- modulename: test, funcname: <module>test.py(1): import systest.py(2): print(sys.version)3.12.0b2 (main, Jun  7 2023, 08:47:18) [Clang 14.0.3 (clang-1403.0.22.14.1)]test.py(4): def example(raise_exc: bool, enter_finally_cond: bool):test.py(16): try:test.py(17):     example(raise_exc=True, enter_finally_cond=True) --- modulename: test, funcname: exampletest.py(5):     try:test.py(6):         if raise_exc:test.py(7):             print("raising exception")raising exceptiontest.py(8):             raise Exceptiontest.py(11):         if enter_finally_cond:test.py(12):             print("in finally conditional")in finally conditionaltest.py(11):         if enter_finally_cond:             # <******test.py(18): except:test.py(19):     pass

The extra line is marked with<******. There's no reason for the if statement to be traced again.

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp