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
Gwenaël Samain
cython
Commits
cfc20700
Commit
cfc20700
authored
May 10, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix optimisation of isinstance(X, type)
parent
25401383
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+6
-1
tests/run/isinstance.pyx
tests/run/isinstance.pyx
+15
-4
No files found.
Cython/Compiler/Optimize.py
View file @
cfc20700
...
@@ -2090,7 +2090,12 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
...
@@ -2090,7 +2090,12 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
entry
=
env
.
lookup
(
test_type_node
.
entry
.
name
)
entry
=
env
.
lookup
(
test_type_node
.
entry
.
name
)
if
entry
and
entry
.
type
and
entry
.
type
.
is_builtin_type
:
if
entry
and
entry
.
type
and
entry
.
type
.
is_builtin_type
:
builtin_type
=
entry
.
type
builtin_type
=
entry
.
type
if
builtin_type
and
builtin_type
is
not
Builtin
.
type_type
:
if
builtin_type
is
Builtin
.
type_type
:
# all types have type "type", but there's only one 'type'
if
entry
.
name
!=
'type'
or
not
(
entry
.
scope
and
entry
.
scope
.
is_builtin_scope
):
builtin_type
=
None
if
builtin_type
is
not
None
:
type_check_function
=
entry
.
type
.
type_check_function
(
exact
=
False
)
type_check_function
=
entry
.
type
.
type_check_function
(
exact
=
False
)
if
type_check_function
in
tests
:
if
type_check_function
in
tests
:
continue
continue
...
...
tests/run/isinstance.pyx
View file @
cfc20700
...
@@ -21,7 +21,18 @@ def test_non_optimised():
...
@@ -21,7 +21,18 @@ def test_non_optimised():
return
True
return
True
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
,
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
,
'//PythonCapiCallNode//SimpleCallNode'
)
'//PythonCapiCallNode//SimpleCallNode'
,
'//PythonCapiFunctionNode[@cname = "PyType_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyInt_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyFloat_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyBytes_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyUnicode_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyTuple_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyList_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyDict_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PySet_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PySlice_Check"]'
,
'//PythonCapiFunctionNode[@cname = "PyComplex_Check"]'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode//SimpleCallNode'
,
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode//SimpleCallNode'
,
'//SimpleCallNode//PythonCapiCallNode'
)
'//SimpleCallNode//PythonCapiCallNode'
)
def
test_optimised
():
def
test_optimised
():
...
@@ -104,9 +115,9 @@ def test_optimised_tuple():
...
@@ -104,9 +115,9 @@ 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
,
A
))
assert
isinstance
(
int
(),
(
int
,
long
,
float
,
bytes
,
str
,
unicode
,
tuple
,
list
,
dict
,
set
,
slice
,
type
,
A
))
assert
isinstance
(
list
(),
(
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
,
type
,
A
))
assert
isinstance
(
A
(),
(
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
,
type
,
A
))
return
True
return
True
def
test_custom
():
def
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