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
c506034b
Commit
c506034b
authored
Oct 25, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix builtin Exception type checking.
Closes #1496
parent
d8c54671
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
2 deletions
+31
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+6
-1
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+1
-0
tests/run/builtin_type_inheritance_T608.pyx
tests/run/builtin_type_inheritance_T608.pyx
+23
-0
No files found.
Cython/Compiler/Nodes.py
View file @
c506034b
...
@@ -2129,7 +2129,7 @@ class FuncDefNode(StatNode, BlockNode):
...
@@ -2129,7 +2129,7 @@ class FuncDefNode(StatNode, BlockNode):
typeptr_cname
,
typeptr_cname
,
arg
.
accept_none
,
arg
.
accept_none
,
arg
.
name
,
arg
.
name
,
arg
.
type
.
is_builtin_type
,
arg
.
type
.
is_builtin_type
and
arg
.
type
.
require_exact
,
code
.
error_goto
(
arg
.
pos
)))
code
.
error_goto
(
arg
.
pos
)))
else
:
else
:
error
(
arg
.
pos
,
"Cannot test type of extern C class without type object name specification"
)
error
(
arg
.
pos
,
"Cannot test type of extern C class without type object name specification"
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
c506034b
...
@@ -1138,6 +1138,7 @@ class BuiltinObjectType(PyObjectType):
...
@@ -1138,6 +1138,7 @@ class BuiltinObjectType(PyObjectType):
has_attributes
=
1
has_attributes
=
1
base_type
=
None
base_type
=
None
module_name
=
'__builtin__'
module_name
=
'__builtin__'
require_exact
=
1
# fields that let it look like an extension type
# fields that let it look like an extension type
vtabslot_cname
=
None
vtabslot_cname
=
None
...
@@ -1157,6 +1158,8 @@ class BuiltinObjectType(PyObjectType):
...
@@ -1157,6 +1158,8 @@ class BuiltinObjectType(PyObjectType):
# Special case the type type, as many C API calls (and other
# Special case the type type, as many C API calls (and other
# libraries) actually expect a PyTypeObject* for type arguments.
# libraries) actually expect a PyTypeObject* for type arguments.
self
.
decl_type
=
objstruct_cname
self
.
decl_type
=
objstruct_cname
if
name
==
'Exception'
:
self
.
require_exact
=
0
def
set_scope
(
self
,
scope
):
def
set_scope
(
self
,
scope
):
self
.
scope
=
scope
self
.
scope
=
scope
...
@@ -1210,13 +1213,15 @@ class BuiltinObjectType(PyObjectType):
...
@@ -1210,13 +1213,15 @@ class BuiltinObjectType(PyObjectType):
type_check
=
'PyString_Check'
type_check
=
'PyString_Check'
elif
type_name
==
'basestring'
:
elif
type_name
==
'basestring'
:
type_check
=
'__Pyx_PyBaseString_Check'
type_check
=
'__Pyx_PyBaseString_Check'
elif
type_name
==
'Exception'
:
type_check
=
'__Pyx_PyException_Check'
elif
type_name
==
'bytearray'
:
elif
type_name
==
'bytearray'
:
type_check
=
'PyByteArray_Check'
type_check
=
'PyByteArray_Check'
elif
type_name
==
'frozenset'
:
elif
type_name
==
'frozenset'
:
type_check
=
'PyFrozenSet_Check'
type_check
=
'PyFrozenSet_Check'
else
:
else
:
type_check
=
'Py%s_Check'
%
type_name
.
capitalize
()
type_check
=
'Py%s_Check'
%
type_name
.
capitalize
()
if
exact
and
type_name
not
in
(
'bool'
,
'slice'
):
if
exact
and
type_name
not
in
(
'bool'
,
'slice'
,
'Exception'
):
type_check
+=
'Exact'
type_check
+=
'Exact'
return
type_check
return
type_check
...
...
Cython/Utility/ModuleSetupCode.c
View file @
c506034b
...
@@ -308,6 +308,7 @@
...
@@ -308,6 +308,7 @@
#endif
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
#if PY_MAJOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject
#define PyIntObject PyLongObject
...
...
tests/run/builtin_type_inheritance_T608.pyx
View file @
c506034b
...
@@ -125,3 +125,26 @@ cdef class MyException(Exception):
...
@@ -125,3 +125,26 @@ cdef class MyException(Exception):
cdef
readonly
int
value
cdef
readonly
int
value
def
__cinit__
(
self
,
value
):
def
__cinit__
(
self
,
value
):
self
.
value
=
value
self
.
value
=
value
def
test_exception_isinstance
(
maybe_exn
):
"""
>>> test_exception_isinstance(Exception())
True
>>> test_exception_isinstance(MyException(3))
True
>>> test_exception_isinstance(3)
False
"""
return
isinstance
(
maybe_exn
,
Exception
)
def
test_exception_type_cast
(
Exception
maybe_exn
):
"""
>>> test_exception_type_cast(Exception())
>>> test_exception_type_cast(MyException(3))
>>> test_exception_type_cast(3) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: Argument 'maybe_exn' has incorrect type (expected ...Exception, got int)
"""
cdef
object
o
=
maybe_exn
cdef
Exception
e
=
o
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