Commit 87fbdd72 authored by Stefan Behnel's avatar Stefan Behnel

be a bit smarter about when slicing or item access return None

--HG--
extra : amend_source : 51a4e6ec35c70af746630fcada3982c2decde872
parent 89e7e32c
...@@ -839,7 +839,7 @@ class ExprNode(Node): ...@@ -839,7 +839,7 @@ class ExprNode(Node):
if self.type and not (self.type.is_pyobject or if self.type and not (self.type.is_pyobject or
self.type.is_memoryviewslice): self.type.is_memoryviewslice):
return False return False
if self.constant_result not in (not_a_constant, constant_value_not_set): if self.has_constant_result():
return self.constant_result is not None return self.constant_result is not None
return True return True
...@@ -2767,6 +2767,18 @@ class IndexNode(ExprNode): ...@@ -2767,6 +2767,18 @@ class IndexNode(ExprNode):
return (base.is_simple() and self.index.is_simple() return (base.is_simple() and self.index.is_simple()
and base.type and (base.type.is_ptr or base.type.is_array)) and base.type and (base.type.is_ptr or base.type.is_array))
def may_be_none(self):
base_type = self.base.type
if base_type:
if base_type.is_string:
return False
if isinstance(self.index, SliceNode):
# slicing!
if base_type in (bytes_type, str_type, unicode_type,
basestring_type, list_type, tuple_type):
return False
return ExprNode.may_be_none(self)
def analyse_target_declaration(self, env): def analyse_target_declaration(self, env):
pass pass
...@@ -3714,12 +3726,22 @@ class SliceIndexNode(ExprNode): ...@@ -3714,12 +3726,22 @@ class SliceIndexNode(ExprNode):
elif base_type.is_pyunicode_ptr: elif base_type.is_pyunicode_ptr:
return unicode_type return unicode_type
elif base_type in (bytes_type, str_type, unicode_type, elif base_type in (bytes_type, str_type, unicode_type,
list_type, tuple_type): basestring_type, list_type, tuple_type):
return base_type return base_type
elif base_type.is_ptr or base_type.is_array: elif base_type.is_ptr or base_type.is_array:
return PyrexTypes.c_array_type(base_type.base_type, None) return PyrexTypes.c_array_type(base_type.base_type, None)
return py_object_type return py_object_type
def may_be_none(self):
base_type = self.base.type
if base_type:
if base_type.is_string:
return False
if base_type in (bytes_type, str_type, unicode_type,
basestring_type, list_type, tuple_type):
return False
return ExprNode.may_be_none(self)
def calculate_constant_result(self): def calculate_constant_result(self):
if self.start is None: if self.start is None:
start = None start = None
......
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