GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Nested AttributeError improved messages don't work with properties · Issue #146171 · python/cpython

Nested AttributeError improved messages don't work with properties #146171

New issue
Copy link
New issue
Copy link
Closed
Closed
Nested AttributeError improved messages don't work with properties#146171
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@rodrigogiraoserrao
rodrigogiraoserrao
opened on Mar 19, 2026
Issue body actions

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:

from dataclasses import dataclass

@dataclass
class Circle:
   radius: float

   @property
   def area(self) -> float:
      return pi * self.radius**2

class Container:
   def __init__(self, inner: Circle) -> None:
      self.inner = inner

circle = 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 (most recent call last):
  File "/Users/rodrigogs/Documents/cpython/../tmp/circle.py", line 17, in <module>
    print(container.area)
          ^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute '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 (most recent call last):
  File "/Users/rodrigogs/Documents/cpython/../tmp/circle_no_prop.py", line 16, in <module>
    print(container.area)
          ^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute 'area'. Did you mean: 'inner.area'?

# ---

# Accessing `radius` instead of the property `area`:
Traceback (most recent call last):
  File "/Users/rodrigogs/Documents/cpython/../tmp/circle_radius.py", line 17, in <module>
    print(container.radius)
          ^^^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute 'radius'. Did you mean: 'inner.radius'?

Helper scripts for easier testing

circle.py — original example that doesn't work
from dataclasses import dataclass

@dataclass
class Circle:
   radius: float

   @property
   def area(self) -> float:
      return pi * self.radius**2

class Container:
   def __init__(self, inner: Circle) -> None:
      self.inner = inner

circle = Circle(radius=4.0)
container = Container(circle)
print(container.area)
circle_radius.py — accessing radius works
from dataclasses import dataclass

@dataclass
class Circle:
   radius: float

   @property
   def area(self) -> float:
      return pi * self.radius**2

class Container:
   def __init__(self, inner: Circle) -> None:
      self.inner = inner

circle = Circle(radius=4.0)
container = Container(circle)
print(container.radius)
circle_no_prop.py — removing the property works
from dataclasses import dataclass

@dataclass
class Circle:
   radius: float

   # @property
   def area(self) -> float:
      return pi * self.radius**2

class Container:
   def __init__(self, inner: Circle) -> None:
      self.inner = inner

circle = 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

  • gh-146171: Fix nested AttributeError suggestions #146188

Activity

  1. rodrigogiraoserrao
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 19, 2026
  2. hugovk commented on Mar 19, 2026

    @hugovk
    hugovk
    on Mar 19, 2026
    Member
    More actions

    cc @pablogsal

  3. StanFromIreland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Mar 19, 2026
  4. okiemute04 commented on Mar 19, 2026

    @okiemute04
    okiemute04
    on Mar 19, 2026
    Contributor
    More actions

    @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?

  5. pablogsal
    added a commit that references this issue on Mar 20, 2026

    pythongh-146171: Fix nested AttributeError suggestions

    4393431
  6. pablogsal commented on Mar 20, 2026

    @pablogsal
    pablogsal
    on Mar 20, 2026
    Member
    More actions

    @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!

  7. pablogsal commented on Mar 20, 2026

    @pablogsal
    pablogsal
    on Mar 20, 2026
    Member
    More actions

    Thanks @rodrigogiraoserrao for the find! ❤️

    Reacted by Hugo van Kemenade
    Reacted by Rodrigo Girão Serrão
  8. okiemute04 commented on Mar 20, 2026

    @okiemute04
    okiemute04
    on Mar 20, 2026
    Contributor
    More actions

    @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 Salgado
  9. pablogsal commented on Mar 20, 2026

    @pablogsal
    pablogsal
    on Mar 20, 2026
    Member
    More actions

    Thanks a lot @okiemute04 🖤

    Reacted by Okiemute Enato
  10. pablogsal
    added a commit that references this issue on Mar 20, 2026

    gh-146171: Fix nested AttributeError suggestions (#146188)

    2f4eb34
  11. pablogsal
    closed this as completedon Mar 20, 2026
  12. rodrigogiraoserrao commented on Mar 20, 2026

    @rodrigogiraoserrao
    rodrigogiraoserrao
    on Mar 20, 2026
    ContributorAuthor
    More actions

    Well, that was quick. 👀 Thanks to both!

    Reacted by Hugo van Kemenade
  13. CuriousLearner
    added a commit that references this issue on Mar 22, 2026

    Merge remote-tracking branch 'upstream/main' into fix-pythongh-138577

    2691ad9
  14. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146171: Fix nested AttributeError suggestions (python#146188)

    240126d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.