]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-146406: Add cross-language method suggestions for builtin AttributeError (#146407)
authorMatt Van Horn <mvanhorn@users.noreply.github.com>
Mon, 4 May 2026 21:38:07 +0000 (14:38 -0700)
committerGitHub <noreply@github.com>
Mon, 4 May 2026 21:38:07 +0000 (21:38 +0000)
commit7acee984e8e2a88bcfb7a83e9c472902e340e5be
tree0620ec7c2cc364e86b1835e4b413391f220c647d
parente89568f0cbcfd055419cdde5ac1248cb48055f90
gh-146406: Add cross-language method suggestions for builtin AttributeError (#146407)

When Levenshtein-based suggestions find no match for an AttributeError
on list, str, or dict, check a static table of common method names from
JavaScript, Java, C#, and Ruby.

For example, [].push() now suggests .append(), "".toUpperCase() suggests
.upper(), and {}.keySet() suggests .keys().

The list.add() case suggests using a set instead of suggesting .append(),
since .add() is a set method and the user may have passed a list where
a set was expected (per discussion with Serhiy Storchaka, Terry Reedy,
and Paul Moore).

Design: flat (type, attr) -> suggestion text table, no runtime
introspection. Only exact builtin types are matched to avoid false
positives on subclasses.

Discussion: https://discuss.python.org/t/106632

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Doc/whatsnew/3.15.rst
Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS.d/next/Library/2026-03-25-07-17-41.gh-issue-146406.ydsmqe.rst [new file with mode: 0644]