python / python/cpython

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

Open
#148,306 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-repl type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-148317

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Lib/dis.py around dis.distb() line 150 and reproduce the reported REPL sequence: import dis, enter invalid code, then call dis.distb(). Done means the final command no longer raises AttributeError after the preceding compilation failure; check the linked gh-148317 work before starting.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.