New submission from pasenor <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue39865>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com