[New-bugs-announce] [issue4020] hasattr boundary case failure
Xore
report at bugs.python.org
Thu Oct 2 21:06:41 CEST 2008
New submission from Xore <xore.ander at gmail.com>:
http://www.python.org/doc/2.5.2/lib/built-in-funcs.html#l2h-35
"(This is implemented by calling getattr(object, name) and seeing
whether it raises an exception or not.)"
If a property exists but it's retrieval throws some error, hasattr will
interpret this as the property not existing, since it only checks for
the existence of an error, not an AttributeError
<code>
class test:
@property
def prop(self):
# do stuff
raise ZeroDivisionError # an example
foobar = test()
assert hasattr(foobar, "prop")
</code>
----------
messages: 74187
nosy: Xore
severity: normal
status: open
title: hasattr boundary case failure
type: behavior
versions: Python 2.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4020>
_______________________________________
More information about the New-bugs-announce
mailing list