[issue39865] getattr silences an unrelated AttributeError
pasenor
report at bugs.python.org
Thu Mar 5 14:24:01 EST 2020
New submission from pasenor <gosha at fro.lv>:
if a class has a descriptor and a defined __getattr__ method, and an AttributeError (unrelated to the descriptor lookup) is raised inside the descriptor, it will be silenced:
class A:
@property
def myprop(self):
print("property called")
a = 1
a.foo # <-- AttributeError that should not be silenced
def __getattr__(self, attr_name):
print("__getattr__ called")
a = A()
a.myprop
In this example myprop() is called, the error silenced, then __getattr__() is called.
This can lead to rather subtle bugs. Probably an explicit AttributeError should be raised instead.
----------
messages: 363449
nosy: pasenor
priority: normal
severity: normal
status: open
title: getattr silences an unrelated AttributeError
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39865>
_______________________________________
More information about the Python-bugs-list
mailing list