Repository navigation
Nested AttributeError improved messages don't work with properties #146171
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 19, 2026 cc @pablogsal
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Mar 19, 2026 @rodrigogiraoserrao just analyzed the issue. The problem is that the nested attribute suggestion system doesn't understand properties. My proposed solution is to enhance the error suggestion algorithm to recognize property descriptors and examine their getter functions when generating suggestions. This would maintain the existing behavior for regular attributes while adding property support. What do you think? Any suggestions or options that will be a good fit for this issue?
- added a commit that references this issue
on Mar 20, 2026 @rodrigogiraoserrao just analyzed the issue. The problem is that the nested attribute suggestion system doesn't understand properties. My proposed solution is to enhance the error suggestion algorithm to recognize property descriptors and examine their getter functions when generating suggestions. This would maintain the existing behavior for regular attributes while adding property support. What do you think? Any suggestions or options that will be a good fit for this issue?
Sorry, I didn't read this message earlier.
I ended up taking a slightly different approach from examining the getter function directly. The fix uses static attribute lookup for nested suggestions, so property-backed attributes can be suggested without executing the property getter. That keeps the existing behavior for regular attributes and avoids triggering arbitrary code while formatting the error.
If you want to help, reviewing the change and testing a few edge cases would be useful!
Thanks @rodrigogiraoserrao for the find! ❤️
Reacted by Hugo van KemenadeReacted by Rodrigo Girão Serrão@pablogsal I tested this PR locally with the property example from #146171 and confirmed:
✅ The property getter is not executed (no side effects)
✅ The tests test_getattr_nested_with_property passed and are working as they should
✅ The error message correctly suggests inner.computed for the property-backed attribute
Great work !!!!!!!!!!
Reacted by Pablo Galindo SalgadoThanks a lot @okiemute04 🖤
Reacted by Okiemute Enatorodrigogiraoserrao commented
on Mar 20, 2026 ContributorAuthorMore actionsWell, that was quick. 👀 Thanks to both!
Reacted by Hugo van Kemenade
The Python 3.15 improved error message for nested attribute access doesn't seem to work on properties.
Rationale
Take the example from the What's new in Python 3.15 docs:
Running it with the CPython main branch or Python 3.15.0a1 through Python 3.15.0a7 (with uv) produces the following error:
If you remove
@propertyor if you try accessingcontainer.radiusinstead, you get the respective improved messages:Helper scripts for easier testing
circle.py— original example that doesn't workcircle_radius.py— accessing radius workscircle_no_prop.py— removing the property worksCPython versions tested on:
3.15, CPython main branch
Operating systems tested on:
macOS
Linked PRs