Skip to content

Commit 579d037

Browse files
committed
Add What's New entry for cross-language AttributeError hints
1 parent 6d58cdc commit 579d037

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,29 @@ Improved error messages
420420
^^^^^^^^^^^^^^
421421
AttributeError: 'Container' object has no attribute 'area'. Did you mean '.inner.area' instead of '.area'?
422422
423+
* When an :exc:`AttributeError` on a builtin type has no close match via
424+
Levenshtein distance, the error message now checks a static table of common
425+
method names from other languages (JavaScript, Java, Ruby, C#) and suggests
426+
the Python equivalent:
427+
428+
.. code-block:: pycon
429+
430+
>>> [1, 2, 3].push(4)
431+
AttributeError: 'list' object has no attribute 'push'. Did you mean '.append'?
432+
433+
>>> 'hello'.toUpperCase()
434+
AttributeError: 'str' object has no attribute 'toUpperCase'. Did you mean '.upper'?
435+
436+
When the Python equivalent is a language construct rather than a method,
437+
the hint describes the construct directly:
438+
439+
.. code-block:: pycon
440+
441+
>>> {}.put("a", 1)
442+
AttributeError: 'dict' object has no attribute 'put'. Use dict[key] = value for item assignment
443+
444+
(Contributed by Matt Van Horn in :gh:`146406`.)
445+
423446

424447
Other language changes
425448
======================

0 commit comments

Comments
 (0)