diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py index 7f1e985101f..9e11e518f61 100644 --- a/Lib/test/test_range.py +++ b/Lib/test/test_range.py @@ -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) + self.assertWarns(DeprecationWarning, rangeiter_type, 1, 3, 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) + with test.support.check_warnings(('', DeprecationWarning)): + # rangeiter_new doesn't take keyword arguments + with self.assertRaises(TypeError): + rangeiter_type(a=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) + # 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) - # step mustn't be zero - self.assertRaises(ValueError, rangeiter_type, 1, 1, 0) + # 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): diff --git a/Misc/NEWS b/Misc/NEWS index cde11acc8fb..fb6e3b9f937 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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. diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index eb1861192d9..8449fc7a24d 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -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; }