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:
fromdataclassesimportdataclass@dataclassclassCircle:
radius: float@propertydefarea(self) ->float:
returnpi*self.radius**2classContainer:
def__init__(self, inner: Circle) ->None:
self.inner=innercircle=Circle(radius=4.0)
container=Container(circle)
print(container.area)
Running it with the CPython main branch or Python 3.15.0a1 through Python 3.15.0a7 (with uv) produces the following error:
Traceback (mostrecentcalllast):
File"/Users/rodrigogs/Documents/cpython/../tmp/circle.py", line17, in<module>print(container.area)
^^^^^^^^^^^^^^AttributeError: 'Container'objecthasnoattribute'area'
If you remove @property or if you try accessing container.radius instead, you get the respective improved messages:
# After removing `@property` from `area`:Traceback (mostrecentcalllast):
File"/Users/rodrigogs/Documents/cpython/../tmp/circle_no_prop.py", line16, in<module>print(container.area)
^^^^^^^^^^^^^^AttributeError: 'Container'objecthasnoattribute'area'. Didyoumean: 'inner.area'?
# ---# Accessing `radius` instead of the property `area`:Traceback (mostrecentcalllast):
File"/Users/rodrigogs/Documents/cpython/../tmp/circle_radius.py", line17, in<module>print(container.radius)
^^^^^^^^^^^^^^^^AttributeError: 'Container'objecthasnoattribute'radius'. Didyoumean: 'inner.radius'?
Helper scripts for easier testing
circle.py — original example that doesn't work
fromdataclassesimportdataclass@dataclassclassCircle:
radius: float@propertydefarea(self) ->float:
returnpi*self.radius**2classContainer:
def__init__(self, inner: Circle) ->None:
self.inner=innercircle=Circle(radius=4.0)
container=Container(circle)
print(container.area)
circle_radius.py — accessing radius works
fromdataclassesimportdataclass@dataclassclassCircle:
radius: float@propertydefarea(self) ->float:
returnpi*self.radius**2classContainer:
def__init__(self, inner: Circle) ->None:
self.inner=innercircle=Circle(radius=4.0)
container=Container(circle)
print(container.radius)
circle_no_prop.py — removing the property works
fromdataclassesimportdataclass@dataclassclassCircle:
radius: float# @propertydefarea(self) ->float:
returnpi*self.radius**2classContainer:
def__init__(self, inner: Circle) ->None:
self.inner=innercircle=Circle(radius=4.0)
container=Container(circle)
print(container.area)
CPython versions tested on:
3.15, CPython main branch
Operating systems tested on:
macOS
Linked PRs
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