Commit 25920642 authored by Stefan Behnel's avatar Stefan Behnel

prevent redundant type checks for None values, especially in cascaded assignments

parent eb1e7173
...@@ -699,7 +699,7 @@ class ExprNode(Node): ...@@ -699,7 +699,7 @@ class ExprNode(Node):
else: else:
src = CoerceToPyTypeNode(src, env, type=dst_type) src = CoerceToPyTypeNode(src, env, type=dst_type)
if not src.type.subtype_of(dst_type): if not src.type.subtype_of(dst_type):
if not isinstance(src, NoneNode): if src.constant_result is not None:
src = PyTypeTestNode(src, dst_type, env) src = PyTypeTestNode(src, dst_type, env)
elif src.type.is_pyobject: elif src.type.is_pyobject:
src = CoerceFromPyTypeNode(dst_type, src, env) src = CoerceFromPyTypeNode(dst_type, src, env)
...@@ -10458,6 +10458,7 @@ class ProxyNode(CoercionNode): ...@@ -10458,6 +10458,7 @@ class ProxyNode(CoercionNode):
def __init__(self, arg): def __init__(self, arg):
super(ProxyNode, self).__init__(arg) super(ProxyNode, self).__init__(arg)
self.constant_result = arg.constant_result
self._proxy_type() self._proxy_type()
def analyse_expressions(self, env): def analyse_expressions(self, env):
...@@ -10509,6 +10510,7 @@ class CloneNode(CoercionNode): ...@@ -10509,6 +10510,7 @@ class CloneNode(CoercionNode):
def __init__(self, arg): def __init__(self, arg):
CoercionNode.__init__(self, arg) CoercionNode.__init__(self, arg)
self.constant_result = arg.constant_result
if hasattr(arg, 'type'): if hasattr(arg, 'type'):
self.type = arg.type self.type = arg.type
self.result_ctype = arg.result_ctype self.result_ctype = arg.result_ctype
......
# mode: run # mode: run
# tag: sequence_unpacking # tag: sequence_unpacking
import cython
_set = set _set = set
def _it(N): def _it(N):
...@@ -365,6 +367,7 @@ def unpack_many_int(it): ...@@ -365,6 +367,7 @@ def unpack_many_int(it):
return a,b,c,d,e,f,g,h,i,j,k,l return a,b,c,d,e,f,g,h,i,j,k,l
@cython.test_fail_if_path_exists('//PyTypeTestNode')
def unpack_literal_none_to_builtin_type(): def unpack_literal_none_to_builtin_type():
""" """
>>> unpack_literal_none_to_builtin_type() >>> unpack_literal_none_to_builtin_type()
...@@ -379,6 +382,7 @@ cdef class ExtType: ...@@ -379,6 +382,7 @@ cdef class ExtType:
pass pass
@cython.test_fail_if_path_exists('//PyTypeTestNode')
def unpack_literal_none_to_exttype(): def unpack_literal_none_to_exttype():
""" """
>>> unpack_literal_none_to_exttype() >>> unpack_literal_none_to_exttype()
......
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