Bug report
Bug description:
Example instance of this bug in functools:
fromfunctoolsimportsingledispatchmethodclassC:
@singledispatchmethoddefsdm(self, a):
passC().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:
classC:
foobar=1def__getattr__(self, _):
raiseAttributeErrorC().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
Linked PRs
Bug report
Bug description:
Example instance of this bug in functools:
Traceback gotten (
-) vs. expected (+):The right fix is not to change functools, but to change
traceback.TracebackExceptionto handle bareAttributeErrors (complete the message). It already knows what the attribute is, otherwise it wouldn't compute suggestions.Minimal reproducer:
Backportable to 3.13 and 3.14.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
AttributeErrorandNameError#143813