mirror of
https://github.com/python/cpython.git
synced 2025-10-13 18:33:34 +00:00
Issue #27443: __length_hint__() of bytearray itearator no longer return
negative integer for resized bytearray.
This commit is contained in:
commit
6c94d10a19
3 changed files with 18 additions and 1 deletions
|
@ -1328,6 +1328,16 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
||||||
|
|
||||||
test_exhausted_iterator = test.list_tests.CommonTest.test_exhausted_iterator
|
test_exhausted_iterator = test.list_tests.CommonTest.test_exhausted_iterator
|
||||||
|
|
||||||
|
def test_iterator_length_hint(self):
|
||||||
|
# Issue 27443: __length_hint__ can return negative integer
|
||||||
|
ba = bytearray(b'ab')
|
||||||
|
it = iter(ba)
|
||||||
|
next(it)
|
||||||
|
ba.clear()
|
||||||
|
# Shouldn't raise an error
|
||||||
|
self.assertEqual(list(it), [])
|
||||||
|
|
||||||
|
|
||||||
class AssortedBytesTest(unittest.TestCase):
|
class AssortedBytesTest(unittest.TestCase):
|
||||||
#
|
#
|
||||||
# Test various combinations of bytes and bytearray
|
# Test various combinations of bytes and bytearray
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.6.0 alpha 3
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #27443: __length_hint__() of bytearray itearator no longer return
|
||||||
|
negative integer for resized bytearray.
|
||||||
|
|
||||||
- Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
|
- Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
|
||||||
now return an instance of corresponding subclass.
|
now return an instance of corresponding subclass.
|
||||||
|
|
||||||
|
|
|
@ -2303,8 +2303,12 @@ static PyObject *
|
||||||
bytearrayiter_length_hint(bytesiterobject *it)
|
bytearrayiter_length_hint(bytesiterobject *it)
|
||||||
{
|
{
|
||||||
Py_ssize_t len = 0;
|
Py_ssize_t len = 0;
|
||||||
if (it->it_seq)
|
if (it->it_seq) {
|
||||||
len = PyByteArray_GET_SIZE(it->it_seq) - it->it_index;
|
len = PyByteArray_GET_SIZE(it->it_seq) - it->it_index;
|
||||||
|
if (len < 0) {
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
return PyLong_FromSsize_t(len);
|
return PyLong_FromSsize_t(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue