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
21ca166e
Commit
21ca166e
authored
Oct 08, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28376: Creating instances of range_iterator by calling range_iterator
type now is deprecated. Patch by Oren Milman.
parent
76a6860d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
23 deletions
+36
-23
Lib/test/test_range.py
Lib/test/test_range.py
+26
-23
Misc/NEWS
Misc/NEWS
+3
-0
Objects/rangeobject.c
Objects/rangeobject.c
+7
-0
No files found.
Lib/test/test_range.py
View file @
21ca166e
...
...
@@ -499,29 +499,32 @@ class RangeTest(unittest.TestCase):
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
)
self
.
assertWarns
(
DeprecationWarning
,
rangeiter_type
,
1
,
3
,
1
)
with
test
.
support
.
check_warnings
((
''
,
DeprecationWarning
)):
# 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
):
...
...
Misc/NEWS
View file @
21ca166e
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
Core and Builtins
-----------------
- Issue #28376: Creating instances of range_iterator by calling range_iterator
type now is deprecated. Patch by Oren Milman.
- Issue #28376: The constructor of range_iterator now checks that step is not 0.
Patch by Oren Milman.
...
...
Objects/rangeobject.c
View file @
21ca166e
...
...
@@ -930,6 +930,13 @@ rangeiter_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
long
start
,
stop
,
step
;
if
(
PyErr_WarnEx
(
PyExc_DeprecationWarning
,
"range_iterator(): creating instances of range_iterator "
"by calling range_iterator type is deprecated"
,
1
))
{
return
NULL
;
}
if
(
!
_PyArg_NoKeywords
(
"range_iterator()"
,
kw
))
{
return
NULL
;
}
...
...
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