mirror of
https://github.com/python/cpython.git
synced 2025-09-19 15:10:58 +00:00
Merge 3.1
This commit is contained in:
commit
fa3edbed25
2 changed files with 11 additions and 3 deletions
|
@ -357,6 +357,8 @@ class TestBasicOps(unittest.TestCase):
|
||||||
list(range(maxsize-5, maxsize+5)))
|
list(range(maxsize-5, maxsize+5)))
|
||||||
self.assertEqual(list(islice(count(-maxsize-5), 10)),
|
self.assertEqual(list(islice(count(-maxsize-5), 10)),
|
||||||
list(range(-maxsize-5, -maxsize+5)))
|
list(range(-maxsize-5, -maxsize+5)))
|
||||||
|
self.assertEqual(list(islice(count(10, maxsize+5), 3)),
|
||||||
|
list(range(10, 10+3*(maxsize+5), maxsize+5)))
|
||||||
c = count(3)
|
c = count(3)
|
||||||
self.assertEqual(repr(c), 'count(3)')
|
self.assertEqual(repr(c), 'count(3)')
|
||||||
next(c)
|
next(c)
|
||||||
|
@ -379,6 +381,9 @@ class TestBasicOps(unittest.TestCase):
|
||||||
self.assertEqual(next(copy.deepcopy(c)), value)
|
self.assertEqual(next(copy.deepcopy(c)), value)
|
||||||
self.assertEqual(next(pickle.loads(pickle.dumps(c))), value)
|
self.assertEqual(next(pickle.loads(pickle.dumps(c))), value)
|
||||||
|
|
||||||
|
#check proper internal error handling for large "step' sizes
|
||||||
|
count(1, maxsize+5); sys.exc_info()
|
||||||
|
|
||||||
def test_count_with_stride(self):
|
def test_count_with_stride(self):
|
||||||
self.assertEqual(lzip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
|
self.assertEqual(lzip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
|
||||||
self.assertEqual(lzip('abc',count(start=2,step=3)),
|
self.assertEqual(lzip('abc',count(start=2,step=3)),
|
||||||
|
|
|
@ -3050,6 +3050,7 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
Py_ssize_t cnt = 0;
|
Py_ssize_t cnt = 0;
|
||||||
PyObject *long_cnt = NULL;
|
PyObject *long_cnt = NULL;
|
||||||
PyObject *long_step = NULL;
|
PyObject *long_step = NULL;
|
||||||
|
long step;
|
||||||
static char *kwlist[] = {"start", "step", 0};
|
static char *kwlist[] = {"start", "step", 0};
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:count",
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:count",
|
||||||
|
@ -3087,9 +3088,11 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
assert(long_cnt != NULL && long_step != NULL);
|
assert(long_cnt != NULL && long_step != NULL);
|
||||||
|
|
||||||
/* Fast mode only works when the step is 1 */
|
/* Fast mode only works when the step is 1 */
|
||||||
if (!PyLong_Check(long_step) ||
|
step = PyLong_AsLong(long_step);
|
||||||
PyLong_AS_LONG(long_step) != 1) {
|
if (step != 1) {
|
||||||
slow_mode = 1;
|
slow_mode = 1;
|
||||||
|
if (step == -1 && PyErr_Occurred())
|
||||||
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slow_mode)
|
if (slow_mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue