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
1fb5c964
Commit
1fb5c964
authored
Dec 21, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #632 isinstance bugs.
parent
5b7fac4a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
18 deletions
+22
-18
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+2
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+14
-8
tests/run/isinstance.pyx
tests/run/isinstance.pyx
+6
-10
No files found.
Cython/Compiler/ModuleNode.py
View file @
1fb5c964
...
@@ -579,6 +579,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -579,6 +579,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#endif
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject
#define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type
#define PyInt_Type PyLong_Type
...
...
Cython/Compiler/Optimize.py
View file @
1fb5c964
...
@@ -1986,20 +1986,26 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
...
@@ -1986,20 +1986,26 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
test_nodes
=
[]
test_nodes
=
[]
env
=
self
.
current_env
()
env
=
self
.
current_env
()
for
test_type_node
in
types
:
for
test_type_node
in
types
:
if
not
test_type_node
.
entry
:
builtin_type
=
None
return
node
if
isinstance
(
test_type_node
,
ExprNodes
.
NameNode
):
if
test_type_node
.
entry
:
entry
=
env
.
lookup
(
test_type_node
.
entry
.
name
)
entry
=
env
.
lookup
(
test_type_node
.
entry
.
name
)
if
not
entry
or
not
entry
.
type
or
not
entry
.
type
.
is_builtin_type
:
if
entry
and
entry
.
type
and
entry
.
type
.
is_builtin_type
:
return
node
builtin_type
=
entry
.
type
if
builtin_type
and
builtin_type
is
not
Builtin
.
type_type
:
type_check_function
=
entry
.
type
.
type_check_function
(
exact
=
False
)
type_check_function
=
entry
.
type
.
type_check_function
(
exact
=
False
)
if
not
type_check_function
:
type_check_args
=
[
arg
]
elif
test_type_node
.
type
is
Builtin
.
type_type
:
type_check_function
=
'__Pyx_TypeCheck'
type_check_args
=
[
arg
,
test_type_node
]
else
:
return
node
return
node
if
type_check_function
not
in
tests
:
if
type_check_function
not
in
tests
:
tests
.
append
(
type_check_function
)
tests
.
append
(
type_check_function
)
test_nodes
.
append
(
test_nodes
.
append
(
ExprNodes
.
PythonCapiCallNode
(
ExprNodes
.
PythonCapiCallNode
(
test_type_node
.
pos
,
type_check_function
,
self
.
Py_type_check_func_type
,
test_type_node
.
pos
,
type_check_function
,
self
.
Py_type_check_func_type
,
args
=
[
arg
]
,
args
=
type_check_args
,
is_temp
=
True
,
is_temp
=
True
,
))
))
...
...
tests/run/isinstance.pyx
View file @
1fb5c964
...
@@ -5,8 +5,6 @@ from cpython.bool cimport bool
...
@@ -5,8 +5,6 @@ from cpython.bool cimport bool
cdef
class
A
:
cdef
class
A
:
pass
pass
cdef
an_A
=
A
()
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode//SimpleCallNode'
)
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode//SimpleCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode//PythonCapiCallNode'
,
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode//PythonCapiCallNode'
,
'//PythonCapiCallNode//SimpleCallNode'
)
'//PythonCapiCallNode//SimpleCallNode'
)
...
@@ -50,11 +48,11 @@ def test_optimised():
...
@@ -50,11 +48,11 @@ def test_optimised():
assert
isinstance
(
complex
(),
complex
)
assert
isinstance
(
complex
(),
complex
)
assert
not
isinstance
(
u"foo"
,
int
)
assert
not
isinstance
(
u"foo"
,
int
)
assert
isinstance
(
A
,
type
)
assert
isinstance
(
A
,
type
)
assert
isinstance
(
an_A
,
A
)
assert
isinstance
(
A
()
,
A
)
cdef
type
typed_type
=
A
cdef
type
typed_type
=
A
assert
isinstance
(
an_A
,
typed_type
)
assert
isinstance
(
A
()
,
typed_type
)
cdef
object
untyped_type
=
A
cdef
object
untyped_type
=
A
assert
isinstance
(
an_A
,
<
type
>
untyped_type
)
assert
isinstance
(
A
()
,
<
type
>
untyped_type
)
return
True
return
True
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
...
@@ -66,13 +64,11 @@ def test_optimised_tuple():
...
@@ -66,13 +64,11 @@ def test_optimised_tuple():
>>> test_optimised_tuple()
>>> test_optimised_tuple()
True
True
"""
"""
assert
isinstance
(
int
(),
(
int
,
long
,
float
,
bytes
,
str
,
unicode
,
tuple
,
list
,
dict
,
set
,
slice
))
assert
isinstance
(
int
(),
(
int
,
long
,
float
,
bytes
,
str
,
unicode
,
tuple
,
list
,
dict
,
set
,
slice
,
A
))
assert
isinstance
(
list
(),
(
int
,
long
,
float
,
bytes
,
str
,
unicode
,
tuple
,
list
,
dict
,
set
,
slice
))
assert
isinstance
(
list
(),
(
int
,
long
,
float
,
bytes
,
str
,
unicode
,
tuple
,
list
,
dict
,
set
,
slice
,
A
))
assert
isinstance
(
A
(),
(
int
,
long
,
float
,
bytes
,
str
,
unicode
,
tuple
,
list
,
dict
,
set
,
slice
,
A
))
return
True
return
True
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode//SimpleCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode//PythonCapiCallNode'
,
'//PythonCapiCallNode//SimpleCallNode'
)
def
test_custom
():
def
test_custom
():
"""
"""
>>> test_custom()
>>> test_custom()
...
...
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