File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -420,6 +420,35 @@ 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+ .. doctest ::
429+
430+ >>> [1 , 2 , 3 ].push(4 ) # doctest: +ELLIPSIS
431+ Traceback (most recent call last):
432+ ...
433+ AttributeError: 'list' object has no attribute 'push'. Did you mean '.append'?
434+
435+ >>> ' hello' .toUpperCase() # doctest: +ELLIPSIS
436+ Traceback (most recent call last):
437+ ...
438+ AttributeError: 'str' object has no attribute 'toUpperCase'. Did you mean '.upper'?
439+
440+ When the Python equivalent is a language construct rather than a method,
441+ the hint describes the construct directly:
442+
443+ .. doctest ::
444+
445+ >>> {}.put(" a" , 1 ) # doctest: +ELLIPSIS
446+ Traceback (most recent call last):
447+ ...
448+ AttributeError: 'dict' object has no attribute 'put'. Use dict[key] = value for item assignment
449+
450+ (Contributed by Matt Van Horn in :gh: `146406 `.)
451+
423452
424453Other language changes
425454======================
You can’t perform that action at this time.
0 commit comments