-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as not planned
Closed as not planned
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
There are many reports on the web about this behaviour.
But look at this code and how Python 3.13 reacts:
class Foo:
def __init__(self):
self.bar = None
def __getattr__(self, name):
print(f'catched {name}')
@property
def aproperty(self):
self.bar.foo
def afunc(self):
self.bar.foo
_ = Foo()
_.afunc()
# Traceback (most recent call last):
# File "property-issue.py", line 18, in <module>
# _.afunc()
# ~~~~~~~^^
# File "property-issue.py", line 14, in afunc
# self.bar.foo
# AttributeError: 'NoneType' object has no attribute 'foo'
_.aproperty
# catched aproperty
It looks weird to me. Why Python should react differently for the same code depending on it is defined as a func or a property ?
Moreover, I would expect __getattr__
catch AttributeError
only on Foo.__dict__
.
And a better error reporting and a note on the documentation about this behaviour.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement