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
7c59ebcc
Commit
7c59ebcc
authored
Oct 08, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28376: The constructor of range_iterator now checks that step is not 0.
Patch by Oren Milman.
parent
58aac9fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
3 deletions
+43
-3
Lib/test/test_range.py
Lib/test/test_range.py
+29
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/rangeobject.c
Objects/rangeobject.c
+11
-3
No files found.
Lib/test/test_range.py
View file @
7c59ebcc
...
...
@@ -493,6 +493,35 @@ class RangeTest(unittest.TestCase):
test_id
=
"reversed(range({}, {}, {}))"
.
format
(
start
,
end
,
step
)
self
.
assert_iterators_equal
(
iter1
,
iter2
,
test_id
,
limit
=
100
)
@
test
.
support
.
cpython_only
def
test_range_iterator_invocation
(
self
):
import
_testcapi
rangeiter_type
=
type
(
iter
(
range
(
0
)))
# rangeiter_new doesn't take keyword arguments
with
self
.
assertRaises
(
TypeError
):
rangeiter_type
(
a
=
1
)
# rangeiter_new takes exactly 3 arguments
self
.
assertRaises
(
TypeError
,
rangeiter_type
)
self
.
assertRaises
(
TypeError
,
rangeiter_type
,
1
)
self
.
assertRaises
(
TypeError
,
rangeiter_type
,
1
,
1
)
self
.
assertRaises
(
TypeError
,
rangeiter_type
,
1
,
1
,
1
,
1
)
# start, stop and stop must fit in C long
for
good_val
in
[
_testcapi
.
LONG_MAX
,
_testcapi
.
LONG_MIN
]:
rangeiter_type
(
good_val
,
good_val
,
good_val
)
for
bad_val
in
[
_testcapi
.
LONG_MAX
+
1
,
_testcapi
.
LONG_MIN
-
1
]:
self
.
assertRaises
(
OverflowError
,
rangeiter_type
,
bad_val
,
1
,
1
)
self
.
assertRaises
(
OverflowError
,
rangeiter_type
,
1
,
bad_val
,
1
)
self
.
assertRaises
(
OverflowError
,
rangeiter_type
,
1
,
1
,
bad_val
)
# step mustn't be zero
self
.
assertRaises
(
ValueError
,
rangeiter_type
,
1
,
1
,
0
)
def
test_slice
(
self
):
def
check
(
start
,
stop
,
step
=
None
):
i
=
slice
(
start
,
stop
,
step
)
...
...
Misc/NEWS
View file @
7c59ebcc
...
...
@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
-----------------
- Issue #28376: The constructor of range_iterator now checks that step is not 0.
Patch by Oren Milman.
- Issue #26906: Resolving special methods of uninitialized type now causes
implicit initialization of the type instead of a fail.
...
...
Objects/rangeobject.c
View file @
7c59ebcc
...
...
@@ -937,12 +937,20 @@ rangeiter_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
long
start
,
stop
,
step
;
if
(
!
_PyArg_NoKeywords
(
"range
iter()"
,
kw
))
if
(
!
_PyArg_NoKeywords
(
"range
_iterator()"
,
kw
))
{
return
NULL
;
}
if
(
!
PyArg_ParseTuple
(
args
,
"lll;rangeiter() requires 3 int arguments"
,
&
start
,
&
stop
,
&
step
))
if
(
!
PyArg_ParseTuple
(
args
,
"lll;range_iterator() requires 3 int arguments"
,
&
start
,
&
stop
,
&
step
))
{
return
NULL
;
}
if
(
step
==
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"range_iterator() arg 3 must not be zero"
);
return
NULL
;
}
return
fast_range_iter
(
start
,
stop
,
step
);
}
...
...
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