File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
424447Other language changes
425448======================
You can’t perform that action at this time.
0 commit comments