Skip to content

Provide NameError/AttributeError suggestions in traceback.py #97008

Closed
@ambv

Description

@ambv

Python 3.10 added NameError and AttributeError suggestions in raised exceptions, in the form of:

>>> dim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'dim' is not defined. Did you mean: 'dir'?

This is implemented in Python/suggestions.c and unavailable in the pure Python implementation of traceback formatting in Lib/traceback.py. This makes the output of both different, which is problematic for tooling using traceback.py, as well as for alternative implementations of Python like PyPy and GraalPy.

Let's implement the equivalent of suggestions.c in Lib/traceback.py to bring both in line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions