[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>:


"(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

class test:
    def prop(self):
        # do stuff
        raise ZeroDivisionError # an example

foobar = test()

assert hasattr(foobar, "prop")

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>

More information about the New-bugs-announce mailing list