Commit cfc20700 authored by Stefan Behnel's avatar Stefan Behnel

fix optimisation of isinstance(X, type)

parent 25401383
......@@ -2090,7 +2090,12 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
entry = env.lookup(test_type_node.entry.name)
if entry and entry.type and entry.type.is_builtin_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)
if type_check_function in tests:
continue
......
......@@ -21,7 +21,18 @@ def test_non_optimised():
return True
@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',
'//SimpleCallNode//PythonCapiCallNode')
def test_optimised():
......@@ -104,9 +115,9 @@ def test_optimised_tuple():
>>> test_optimised_tuple()
True
"""
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, A))
assert isinstance(A(), (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, type, A))
assert isinstance(A(), (int, long, float, bytes, str, unicode, tuple, list, dict, set, slice, type, A))
return True
def test_custom():
......
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