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

traceback.walk_stack(None) does not behave the same as traceback.walk_stack(inspect.currentframe()) #96092

Closed
Labels
3.10only security fixes3.11only security fixes3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@VincentVanlaer

Description

@VincentVanlaer

Bug report

traceback.walk_stack(None) omits the calling frame, making it equivalent totraceback.walk_stack(inspect.currentframe().f_back). Given the documentation just says "If f is None, the current stack is used.", I would have expectedtraceback.walk_stack(None) to be equivalent totraceback.walk_stack(inspect.currentframe()).

Example code

The following code

importtracebackimportinspectdefabc():print(list(traceback.walk_stack(None)))print(list(traceback.walk_stack(inspect.currentframe())))print(list(traceback.walk_stack(inspect.currentframe().f_back)))abc()

has as output

[(<frame at 0x7f66ac559a40, file '/home/vincenttc/data/temp/test/test.py', line 10, code <module>>, 10)][(<frame at 0x7f66ac55fa60, file '/home/vincenttc/data/temp/test/test.py', line 7, code abc>, 7), (<frame at 0x7f66ac559a40, file '/home/vincenttc/data/temp/test/test.py', line 10, code <module>>, 10)][(<frame at 0x7f66ac559a40, file '/home/vincenttc/data/temp/test/test.py', line 10, code <module>>, 10)]

Note that the frame forabc is missing in the first and last line.

Your environment

  • CPython versions tested on: 3.8.10 (Ubuntu 20.04), 3.10.5 (Arch Linux)

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp