Commit aae9d0c4 authored by Stefan Behnel's avatar Stefan Behnel

type inference for SliceIndexNode

parent 0f9f7f1f
...@@ -2073,6 +2073,15 @@ class SliceIndexNode(ExprNode): ...@@ -2073,6 +2073,15 @@ class SliceIndexNode(ExprNode):
subexprs = ['base', 'start', 'stop'] subexprs = ['base', 'start', 'stop']
def infer_type(self, env):
base_type = self.base.infer_type(env)
if base_type.is_string:
return bytes_type
elif base_type in (bytes_type, str_type, unicode_type,
list_type, tuple_type):
return base_type
return py_object_type
def calculate_constant_result(self): def calculate_constant_result(self):
self.constant_result = self.base.constant_result[ self.constant_result = self.base.constant_result[
self.start.constant_result : self.stop.constant_result] self.start.constant_result : self.stop.constant_result]
......
...@@ -46,6 +46,27 @@ def builtin_types(): ...@@ -46,6 +46,27 @@ def builtin_types():
B = bool() B = bool()
assert typeof(B) == "bool object", typeof(B) assert typeof(B) == "bool object", typeof(B)
def slicing():
"""
>>> slicing()
"""
b = b"abc"
assert typeof(b) == "char *", typeof(b)
b1 = b[1:2]
assert typeof(b1) == "bytes object", typeof(b1)
u = u"xyz"
assert typeof(u) == "unicode object", typeof(u)
u1 = u[1:2]
assert typeof(u1) == "unicode object", typeof(u1)
L = [1,2,3]
assert typeof(L) == "list object", typeof(L)
L1 = L[1:2]
assert typeof(L1) == "list object", typeof(L1)
t = (4,5,6)
assert typeof(t) == "tuple object", typeof(t)
t1 = t[1:2]
assert typeof(t1) == "tuple object", typeof(t1)
def multiple_assignments(): def multiple_assignments():
""" """
>>> multiple_assignments() >>> multiple_assignments()
......
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