Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
c8f61a66
Commit
c8f61a66
authored
Apr 18, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly catch indexing of None for all Python objects, including all optimised cases
parent
99e88d36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-2
tests/run/index.pyx
tests/run/index.pyx
+9
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
c8f61a66
...
...
@@ -2663,6 +2663,7 @@ class IndexNode(ExprNode):
self
.
base
=
self
.
base
.
coerce_to_pyobject
(
env
)
base_type
=
self
.
base
.
type
if
base_type
.
is_pyobject
:
self
.
base
=
self
.
base
.
as_none_safe_node
(
"'NoneType' object is unsubscriptable"
)
if
self
.
index
.
type
.
is_int
:
if
(
not
setting
and
(
base_type
in
(
list_type
,
tuple_type
))
...
...
@@ -2685,8 +2686,6 @@ class IndexNode(ExprNode):
elif
is_slice
and
base_type
in
(
bytes_type
,
str_type
,
unicode_type
,
list_type
,
tuple_type
):
self
.
type
=
base_type
else
:
if
base_type
is
dict_type
:
self
.
base
=
self
.
base
.
as_none_safe_node
(
"'NoneType' object is unsubscriptable"
)
self
.
type
=
py_object_type
else
:
if
base_type
.
is_ptr
or
base_type
.
is_array
:
...
...
tests/run/index.pyx
View file @
c8f61a66
...
...
@@ -21,8 +21,10 @@ def index_tuple(tuple t, int i):
5
>>> index_tuple((1,1,2,3,5), 100)
Traceback (most recent call last):
...
IndexError: tuple index out of range
>>> index_tuple(None, 0)
Traceback (most recent call last):
TypeError: 'NoneType' object is unsubscriptable
"""
return
t
[
i
]
...
...
@@ -36,8 +38,10 @@ def index_list(list L, int i):
19
>>> index_list([2,3,5,7,11,13,17,19], 100)
Traceback (most recent call last):
...
IndexError: list index out of range
>>> index_list(None, 0)
Traceback (most recent call last):
TypeError: 'NoneType' object is unsubscriptable
"""
return
L
[
i
]
...
...
@@ -59,6 +63,9 @@ def index_object(object o, int i):
Traceback (most recent call last):
...
IndexError: string index out of range
>>> index_object(None, 0)
Traceback (most recent call last):
TypeError: 'NoneType' object is unsubscriptable
"""
return
o
[
i
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment