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
Kirill Smelkov
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
Hide 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
...
@@ -111,7 +111,7 @@ builtin_function_table = [
...
@@ -111,7 +111,7 @@ builtin_function_table = [
t
.
real_type
,
[
t
.
real_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
t
,
None
)
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
t
,
None
)
],
],
is_strict_signature
=
True
,
nogil
=
True
))
is_strict_signature
=
True
,
nogil
=
True
))
for
t
in
(
PyrexTypes
.
c_float_complex_type
,
for
t
in
(
PyrexTypes
.
c_float_complex_type
,
PyrexTypes
.
c_double_complex_type
,
PyrexTypes
.
c_double_complex_type
,
PyrexTypes
.
c_longdouble_complex_type
)
PyrexTypes
.
c_longdouble_complex_type
)
...
@@ -144,7 +144,8 @@ builtin_function_table = [
...
@@ -144,7 +144,8 @@ builtin_function_table = [
utility_code
=
getattr3_utility_code
),
utility_code
=
getattr3_utility_code
),
BuiltinFunction
(
'getattr'
,
"OO"
,
"O"
,
"__Pyx_GetAttr"
,
BuiltinFunction
(
'getattr'
,
"OO"
,
"O"
,
"__Pyx_GetAttr"
,
utility_code
=
getattr_utility_code
),
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"
),
BuiltinFunction
(
'hash'
,
"O"
,
"h"
,
"PyObject_Hash"
),
#('hex', "", "", ""),
#('hex', "", "", ""),
#('id', "", "", ""),
#('id', "", "", ""),
...
...
Cython/Utility/Builtins.c
View file @
c4ba71f4
...
@@ -183,6 +183,30 @@ bad:
...
@@ -183,6 +183,30 @@ bad:
return
NULL
;
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 ////////////////////
//////////////////// Intern.proto ////////////////////
static
PyObject
*
__Pyx_Intern
(
PyObject
*
s
);
/* proto */
static
PyObject
*
__Pyx_Intern
(
PyObject
*
s
);
/* proto */
...
...
tests/run/hasattr.pyx
View file @
c4ba71f4
...
@@ -17,6 +17,8 @@ def wrap_hasattr(obj, name):
...
@@ -17,6 +17,8 @@ def wrap_hasattr(obj, name):
True
True
>>> wrap_hasattr(Foo(), "foo")
>>> wrap_hasattr(Foo(), "foo")
True
True
>>> wrap_hasattr(Foo(), u"foo")
True
>>> wrap_hasattr(Foo(), "spam")
>>> wrap_hasattr(Foo(), "spam")
False
False
>>> wrap_hasattr(Foo(), "bar")
>>> wrap_hasattr(Foo(), "bar")
...
@@ -27,5 +29,9 @@ def wrap_hasattr(obj, name):
...
@@ -27,5 +29,9 @@ def wrap_hasattr(obj, name):
ZeroDivisionError: ...
ZeroDivisionError: ...
>>> wrap_hasattr(Foo(), "baz")
>>> wrap_hasattr(Foo(), "baz")
False
False
>>> hasattr(Foo(), None) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: hasattr(): attribute name must be string
"""
"""
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