You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add back typo detection to sub-attribute access #137967
I remember we used to have this when all the typo-detection machinery was in the C code but somehow that has not survived the transition to the new traceback machinery (or perhaps I am misremembering but I recall adding this originally when we added the first round). Either way this PR ensures that we have a nice error message when the typo is across attribute access:
Traceback (most recent call last):
File "/home/pablogsal/github/python/main/lel.py", line 42, in <module>
print(container.area)
^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute 'area'. Did you mean: 'inner.area'?
Yeah! I think it would make the suggestion easier to understand and to use.
As a user, my interpretation of the current suggestion is that I've written
container instead of inner (which would be the suggestion provided in case
of typo iirc) but in fact, the container part is valid but I've forgotten a
sub attribute.
I hope it makes sense. If it does not, du not worry about it, I've probably
missed something entirely.
Le mer. 20 août 2025, 20:58, Pablo Galindo Salgado ***@***.***>
a écrit :
Yeah! I think it would make the suggestion easier to understand and to use. As a user, my interpretation of the current suggestion is that I've written container instead of inner (which would be the suggestion provided in case of typo iirc) but in fact, the container part is valid but I've forgotten a sub attribute. I hope it makes sense. If it does not, du not worry about it, I've probably missed something entirely. Le mer. 20 août 2025, 20:58, Pablo Galindo Salgado @.***> a écrit : …
Yeah unfortunately is not possible or at least not very easy: at the time we produce the message we don't have access to the variable name the object is assigned to. We could find it in the frame but that's slow and is a but complicated so it will have some performance impact. Furthermore the rest of the similar error messages don't have the name and that will make it a bit inconsistent, so I think I am going to go with this as it is.
Activity
pythongh-137967: Restore suggestions on nested attribute access
pythongh-137967: Restore suggestions on nested attribute access
SylvainDe commentedon Aug 20, 2025
Looks great!
Out of curiosity, is there any way for not having the following suggestion :
AttributeError: 'Container' object has no attribute 'area'. Did you mean: 'container.inner.area'?? (Maybe it'd harder to implement, maybe it's just not wanted in the first place)
pablogsal commentedon Aug 20, 2025
Not sure I follow, are you saying you want
container.inner.areainstead ofinner.area?SylvainDe commentedon Aug 20, 2025
pablogsal commentedon Aug 21, 2025
Yeah unfortunately is not possible or at least not very easy: at the time we produce the message we don't have access to the variable name the object is assigned to. We could find it in the frame but that's slow and is a but complicated so it will have some performance impact. Furthermore the rest of the similar error messages don't have the name and that will make it a bit inconsistent, so I think I am going to go with this as it is.
Thanks for the suggestion though!
SylvainDe commentedon Aug 21, 2025
Sure! That totally makes sense! Thanks for everything you've done for error messages and for replying to my suggestion!
gh-137967: Restore suggestions on nested attribute access (#137968)
pythongh-137967: Fix "Whats New" doc example
pythongh-137967: Fix "Whats New" doc example
gh-137967: Fix "Whats New" doc example (#138028)