Commit c8f61a66 authored by Stefan Behnel's avatar Stefan Behnel

properly catch indexing of None for all Python objects, including all optimised cases

parent 99e88d36
...@@ -2663,6 +2663,7 @@ class IndexNode(ExprNode): ...@@ -2663,6 +2663,7 @@ class IndexNode(ExprNode):
self.base = self.base.coerce_to_pyobject(env) self.base = self.base.coerce_to_pyobject(env)
base_type = self.base.type base_type = self.base.type
if base_type.is_pyobject: if base_type.is_pyobject:
self.base = self.base.as_none_safe_node("'NoneType' object is unsubscriptable")
if self.index.type.is_int: if self.index.type.is_int:
if (not setting if (not setting
and (base_type in (list_type, tuple_type)) and (base_type in (list_type, tuple_type))
...@@ -2685,8 +2686,6 @@ class IndexNode(ExprNode): ...@@ -2685,8 +2686,6 @@ class IndexNode(ExprNode):
elif is_slice and base_type in (bytes_type, str_type, unicode_type, list_type, tuple_type): elif is_slice and base_type in (bytes_type, str_type, unicode_type, list_type, tuple_type):
self.type = base_type self.type = base_type
else: else:
if base_type is dict_type:
self.base = self.base.as_none_safe_node("'NoneType' object is unsubscriptable")
self.type = py_object_type self.type = py_object_type
else: else:
if base_type.is_ptr or base_type.is_array: if base_type.is_ptr or base_type.is_array:
......
...@@ -21,8 +21,10 @@ def index_tuple(tuple t, int i): ...@@ -21,8 +21,10 @@ def index_tuple(tuple t, int i):
5 5
>>> index_tuple((1,1,2,3,5), 100) >>> index_tuple((1,1,2,3,5), 100)
Traceback (most recent call last): Traceback (most recent call last):
...
IndexError: tuple index out of range IndexError: tuple index out of range
>>> index_tuple(None, 0)
Traceback (most recent call last):
TypeError: 'NoneType' object is unsubscriptable
""" """
return t[i] return t[i]
...@@ -36,8 +38,10 @@ def index_list(list L, int i): ...@@ -36,8 +38,10 @@ def index_list(list L, int i):
19 19
>>> index_list([2,3,5,7,11,13,17,19], 100) >>> index_list([2,3,5,7,11,13,17,19], 100)
Traceback (most recent call last): Traceback (most recent call last):
...
IndexError: list index out of range IndexError: list index out of range
>>> index_list(None, 0)
Traceback (most recent call last):
TypeError: 'NoneType' object is unsubscriptable
""" """
return L[i] return L[i]
...@@ -59,6 +63,9 @@ def index_object(object o, int i): ...@@ -59,6 +63,9 @@ def index_object(object o, int i):
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: string index out of range IndexError: string index out of range
>>> index_object(None, 0)
Traceback (most recent call last):
TypeError: 'NoneType' object is unsubscriptable
""" """
return o[i] return o[i]
......
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