Commit ff2fcf40 authored by Robert Bradshaw's avatar Robert Bradshaw

builtin hasattr() does suppresses all exceptions

parent 48627a02
...@@ -76,25 +76,6 @@ bad: ...@@ -76,25 +76,6 @@ bad:
} }
""") """)
hasattr_utility_code = UtilityCode(
proto = """
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); /*proto*/
""",
impl = """
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
PyObject *v = PyObject_GetAttr(o, n);
if (v) {
Py_DECREF(v);
return 1;
}
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
return 0;
}
return -1;
}
""")
globals_utility_code = UtilityCode( globals_utility_code = UtilityCode(
# This is a stub implementation until we have something more complete. # This is a stub implementation until we have something more complete.
# Currently, we only handle the most common case of a read-only dict # Currently, we only handle the most common case of a read-only dict
...@@ -434,8 +415,7 @@ builtin_function_table = [ ...@@ -434,8 +415,7 @@ builtin_function_table = [
utility_code = getattr3_utility_code), # Pyrex compatibility utility_code = getattr3_utility_code), # Pyrex compatibility
BuiltinFunction('globals', "", "O", "__Pyx_Globals", BuiltinFunction('globals', "", "O", "__Pyx_Globals",
utility_code = globals_utility_code), utility_code = globals_utility_code),
BuiltinFunction('hasattr', "OO", "b", "__Pyx_HasAttr", BuiltinFunction('hasattr', "OO", "b", "PyObject_HasAttr"),
utility_code = hasattr_utility_code),
BuiltinFunction('hash', "O", "h", "PyObject_Hash"), BuiltinFunction('hash', "O", "h", "PyObject_Hash"),
#('hex', "", "", ""), #('hex', "", "", ""),
#('id', "", "", ""), #('id', "", "", ""),
......
...@@ -21,9 +21,11 @@ def wrap_hasattr(obj, name): ...@@ -21,9 +21,11 @@ def wrap_hasattr(obj, name):
False False
>>> wrap_hasattr(Foo(), "bar") >>> wrap_hasattr(Foo(), "bar")
False False
>>> wrap_hasattr(Foo(), "baz") #doctest: +ELLIPSIS >>> Foo().baz #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
ZeroDivisionError: ... ZeroDivisionError: ...
>>> wrap_hasattr(Foo(), "baz")
False
""" """
return hasattr(obj, name) return hasattr(obj, name)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment