Skip to content

In REPL dis.distb() raise AttributeError when the previous input fails to compile #148306

@00ll00

Description

@00ll00

Bug report

Bug description:

in REPL input following sequentially

  1. import dis
  2. some invalid code
  3. dis.distb()
>>> import dis
>>> ??? 
  File "<stdin>", line 1
    ???
    ^
SyntaxError: invalid syntax
>>> dis.distb()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    dis.distb()
    ~~~~~~~~~^^
  File "/home/dev/cpython/Lib/dis.py", line 150, in distb
    while tb.tb_next: tb = tb.tb_next
          ^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'tb_next'

It looks like dis.distb() doesn’t handle the case where the previous exception’s traceback could be None in the REPL.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions