Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
ff2fcf40
Commit
ff2fcf40
authored
Jun 07, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builtin hasattr() does suppresses all exceptions
parent
48627a02
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
22 deletions
+4
-22
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+1
-21
tests/run/hasattr.pyx
tests/run/hasattr.pyx
+3
-1
No files found.
Cython/Compiler/Builtin.py
View file @
ff2fcf40
...
@@ -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', "", "", ""),
...
...
tests/run/hasattr.pyx
View file @
ff2fcf40
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment