Skip to content

gh-145413: Fix nested attribute suggestions executing property code - #145414

Closed
Hiumee wants to merge 3 commits into
python:mainfrom
Hiumee:fix-issue-145413
Closed

gh-145413: Fix nested attribute suggestions executing property code#145414
Hiumee wants to merge 3 commits into
python:mainfrom
Hiumee:fix-issue-145413

Conversation

@Hiumee

@HiumeeHiumee commented Mar 2, 2026

Copy link
Copy Markdown

Updated the code of _check_for_nested_attribute to check properties without triggering their code. This approach will still suggest them

Changed a test case to look for side effects and changed some contradictory comments

Updated the news section code to include imports so the code can be tested out of the box

Example

fromdataclassesimportdataclassfrommathimportpi@dataclassclassCircle:
radius: float@propertydefarea(self) ->float:
print("Property 'area' accessed")
returnpi*self.radius**2classContainer:
def__init__(self, inner: Circle) ->None:
self.inner=innercircle=Circle(radius=4.0)
container=Container(circle)
print(container.area)

Output

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
print(container.area)
^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute 'area'. Did you mean '.inner.area' instead of '.area'?

It doesn't reach the print statement at all


📚 Documentation preview 📚: https://cpython-previews--145414.org.readthedocs.build/

@Hiumee
Hiumee requested a review from AA-Turner as a code ownerMarch 2, 2026 11:41
@python-cla-bot

python-cla-botBot commented Mar 2, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@Hiumee

Hiumee commented Mar 26, 2026

Copy link
Copy Markdown
Author

Appears to be fixed by #146188
Would the test case in the PR still be useful to prevent regression?

Edit: It seems the new test case covers it. I'll close the issue and PR

@HiumeeHiumee closed this Mar 26, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@Hiumee