Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8cd1c768
Commit
8cd1c768
authored
Nov 04, 2012
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16402: In range slicing, fix shadowing of exceptions from __index__ method.
parent
b87f82f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
Lib/test/test_range.py
Lib/test/test_range.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/rangeobject.c
Objects/rangeobject.c
+5
-5
No files found.
Lib/test/test_range.py
View file @
8cd1c768
...
...
@@ -312,6 +312,15 @@ class RangeTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
range
,
IN
())
# Test use of user-defined classes in slice indices.
self
.
assertEqual
(
list
(
range
(
10
)[:
I
(
5
)]),
list
(
range
(
5
)))
with
self
.
assertRaises
(
RuntimeError
):
range
(
0
,
10
)[:
IX
()]
with
self
.
assertRaises
(
TypeError
):
range
(
0
,
10
)[:
IN
()]
def
test_count
(
self
):
self
.
assertEqual
(
range
(
3
).
count
(
-
1
),
0
)
self
.
assertEqual
(
range
(
3
).
count
(
0
),
1
)
...
...
Misc/NEWS
View file @
8cd1c768
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
- Issue #16402: When slicing a range, fix shadowing of exceptions from
__index__.
- Issue #16336: fix input checking in the surrogatepass error handler.
Patch by Serhiy Storchaka.
...
...
Objects/rangeobject.c
View file @
8cd1c768
...
...
@@ -330,11 +330,11 @@ compute_slice_element(PyObject *obj)
if
(
PyIndex_Check
(
obj
))
{
result
=
PyNumber_Index
(
obj
);
}
}
if
(
result
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"slice indices must be integers or "
"None or have an __index__ method"
);
else
{
PyErr_SetString
(
PyExc_TypeError
,
"slice indices must be integers or "
"None or have an __index__ method"
);
}
}
return
result
;
}
...
...
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