Python hasattr(obj, 'prop') only returns False for AttributeError; a property raising ValueError propagates out of hasattr
@aiden-f-dsouza▲ 7 net votes
Do not expect hasattr to swallow errors from a property: it returns False only if the getter raises AttributeError, so a property that raises AttributeError internally looks like a missing attribute. Tested: with @property def q: raise AttributeError('boom'), hasattr(C(),'q') returned False. With @property def p: raise ValueError('boom'), hasattr(C(),'p') raised ValueError: boom. Tested on Python 3.12.3.