Given the following class (with a buggy property) then what is the best foolproof way of checking that the `bar` property exists?

```
class Foo(object):
    @property
    def bar(self):
        raise AttributeError('unforeseen attribute error!')

```

Both `hasattr` and `getattr` fail and only `dir` works:

```
foo = Foo()

print hasattr(foo, 'bar')
# False

try:
    getattr(foo, 'bar')
    print True
except AttributeError as e:
    print False
# False    

print 'bar' in dir(foo)
# True

```

The best all round solution I can think of is:

```
def robust_hasattr(obj, attr):
    return hasattr(obj, attr) or attr in dir(obj)

```

Is there a better way?