-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Open
Assignees
@johnslavik
Description
Bug report
Bug description:
Example instance of this bug in functools:
from functools import singledispatchmethod class C: @singledispatchmethod def sdm(self, a): pass C().sdm.__code__
Traceback gotten (-) vs. expected (+):
Traceback (most recent call last): File "<python-input-3>", line 1, in <module> C().sdm.__code__ File "/home/bswck/Python/cpython/Lib/functools.py", line 1096, in __getattr__ raise AttributeError -AttributeError: . Did you mean: '__call__'? +AttributeError: '_singledispatchmethod_get' object has no attribute '__code__'. Did you mean: '__call__'?
The right fix is not to change functools, but to change traceback.TracebackException to handle bare AttributeErrors (complete the message). It already knows what the attribute is, otherwise it wouldn't compute suggestions.
Minimal reproducer:
class C: foobar = 1 def __getattr__(self, _): raise AttributeError C().foboar
Traceback (most recent call last):
File "/home/bswck/Python/cpython/t.py", line 7, in <module>
C().foboar
File "/home/bswck/Python/cpython/t.py", line 5, in __getattr__
raise AttributeError
AttributeError: . Did you mean: 'foobar'?
Backportable to 3.13 and 3.14.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux