Commit fda3c6f4 authored by Stefan Behnel's avatar Stefan Behnel Committed by Robert Bradshaw

fix isinstance() check against a tuple of extension types

parent 6a85d21e
...@@ -1994,14 +1994,15 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): ...@@ -1994,14 +1994,15 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
builtin_type = entry.type builtin_type = entry.type
if builtin_type and builtin_type is not Builtin.type_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 type_check_function in tests:
continue
tests.append(type_check_function)
type_check_args = [arg] type_check_args = [arg]
elif test_type_node.type is Builtin.type_type: elif test_type_node.type is Builtin.type_type:
type_check_function = '__Pyx_TypeCheck' type_check_function = '__Pyx_TypeCheck'
type_check_args = [arg, test_type_node] type_check_args = [arg, test_type_node]
else: else:
return node return node
if type_check_function not in tests:
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,
......
...@@ -77,6 +77,23 @@ def test_custom(): ...@@ -77,6 +77,23 @@ def test_custom():
assert isinstance(A(), A) assert isinstance(A(), A)
return True 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): def test_nested(x):
""" """
>>> test_nested(1) >>> test_nested(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment