This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: hasattr boundary case failure
Type: behavior Stage:
Components: Versions: Python 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Xore, benjamin.peterson
Priority: normal Keywords:

Created on 2008-10-02 19:06 by Xore, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg74187 - (view) Author: Xore (Xore) Date: 2008-10-02 19:06
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>
msg74190 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-02 19:27
This is fixed in 2.6.
History
Date User Action Args
2022-04-11 14:56:39adminsetgithub: 48270
2008-10-02 19:27:36benjamin.petersonsetstatus: open -> closed
resolution: out of date
messages: + msg74190
nosy: + benjamin.peterson
2008-10-02 19:06:40Xorecreate