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
e843204a
Commit
e843204a
authored
13 years ago
by
Stefan Behnel
Committed by
Robert Bradshaw
13 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix isinstance() check against a tuple of extension types
parent
b3028ebb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+9
-8
tests/run/isinstance.pyx
tests/run/isinstance.pyx
+17
-0
No files found.
Cython/Compiler/Optimize.py
View file @
e843204a
...
...
@@ -1994,20 +1994,21 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
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
)
if
type_check_function
in
tests
:
continue
tests
.
append
(
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
if
type_check_function
not
in
tests
:
tests
.
append
(
type_check_function
)
test_nodes
.
append
(
ExprNodes
.
PythonCapiCallNode
(
test_type_node
.
pos
,
type_check_function
,
self
.
Py_type_check_func_type
,
args
=
type_check_args
,
is_temp
=
True
,
))
test_nodes
.
append
(
ExprNodes
.
PythonCapiCallNode
(
test_type_node
.
pos
,
type_check_function
,
self
.
Py_type_check_func_type
,
args
=
type_check_args
,
is_temp
=
True
,
))
def
join_with_or
(
a
,
b
,
make_binop_node
=
ExprNodes
.
binop_node
):
or_node
=
make_binop_node
(
node
.
pos
,
'or'
,
a
,
b
)
...
...
This diff is collapsed.
Click to expand it.
tests/run/isinstance.pyx
View file @
e843204a
...
...
@@ -77,6 +77,23 @@ def test_custom():
assert
isinstance
(
A
(),
A
)
return
True
cdef
class
B
:
pass
cdef
class
C
:
pass
def
test_custom_tuple
(
obj
):
"""
>>> test_custom_tuple(A())
True
>>> test_custom_tuple(B())
True
>>> test_custom_tuple(C())
False
"""
return
isinstance
(
obj
,
(
A
,
B
))
def
test_nested
(
x
):
"""
>>> test_nested(1)
...
...
This diff is collapsed.
Click to expand it.
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