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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
c4ba71f4
Commit
c4ba71f4
authored
May 18, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise TypeError for non-string hasattr.
This fixes #1702.
parent
aa669574
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+3
-2
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+24
-0
tests/run/hasattr.pyx
tests/run/hasattr.pyx
+6
-0
No files found.
Cython/Compiler/Builtin.py
View file @
c4ba71f4
...
...
@@ -144,7 +144,8 @@ builtin_function_table = [
utility_code
=
getattr3_utility_code
),
BuiltinFunction
(
'getattr'
,
"OO"
,
"O"
,
"__Pyx_GetAttr"
,
utility_code
=
getattr_utility_code
),
BuiltinFunction
(
'hasattr'
,
"OO"
,
"b"
,
"PyObject_HasAttr"
),
BuiltinFunction
(
'hasattr'
,
"OO"
,
"b"
,
"__Pyx_HasAttr"
,
utility_code
=
UtilityCode
.
load
(
"HasAttr"
,
"Builtins.c"
)),
BuiltinFunction
(
'hash'
,
"O"
,
"h"
,
"PyObject_Hash"
),
#('hex', "", "", ""),
#('id', "", "", ""),
...
...
Cython/Utility/Builtins.c
View file @
c4ba71f4
...
...
@@ -183,6 +183,30 @@ bad:
return
NULL
;
}
//////////////////// HasAttr.proto ////////////////////
static
CYTHON_INLINE
int
__Pyx_HasAttr
(
PyObject
*
,
PyObject
*
);
/*proto*/
//////////////////// HasAttr ////////////////////
//@requires: ObjectHandling.c::GetAttr
static
CYTHON_INLINE
int
__Pyx_HasAttr
(
PyObject
*
o
,
PyObject
*
n
)
{
PyObject
*
r
;
if
(
unlikely
(
!
__Pyx_PyBaseString_Check
(
n
)))
{
PyErr_SetString
(
PyExc_TypeError
,
"hasattr(): attribute name must be string"
);
return
-
1
;
}
r
=
__Pyx_GetAttr
(
o
,
n
);
if
(
unlikely
(
!
r
))
{
PyErr_Clear
();
return
0
;
}
else
{
Py_DECREF
(
r
);
return
1
;
}
}
//////////////////// Intern.proto ////////////////////
static
PyObject
*
__Pyx_Intern
(
PyObject
*
s
);
/* proto */
...
...
tests/run/hasattr.pyx
View file @
c4ba71f4
...
...
@@ -17,6 +17,8 @@ def wrap_hasattr(obj, name):
True
>>> wrap_hasattr(Foo(), "foo")
True
>>> wrap_hasattr(Foo(), u"foo")
True
>>> wrap_hasattr(Foo(), "spam")
False
>>> wrap_hasattr(Foo(), "bar")
...
...
@@ -27,5 +29,9 @@ def wrap_hasattr(obj, name):
ZeroDivisionError: ...
>>> wrap_hasattr(Foo(), "baz")
False
>>> hasattr(Foo(), None) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: hasattr(): attribute name must be string
"""
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