diff -r b0087e17cd5e Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py Fri Jul 01 17:57:30 2016 +0300 +++ b/Lib/test/test_bytes.py Sat Jul 02 22:52:54 2016 +0300 @@ -1328,6 +1328,14 @@ class ByteArrayTest(BaseBytesTest, unitt test_exhausted_iterator = test.list_tests.CommonTest.test_exhausted_iterator + def test_iterator_length_hint(self): + ba = bytearray(b'ab') + it = iter(ba) + next(it) + ba.clear() + self.assertEqual(list(it), []) + + class AssortedBytesTest(unittest.TestCase): # # Test various combinations of bytes and bytearray diff -r b0087e17cd5e Misc/NEWS --- a/Misc/NEWS Fri Jul 01 17:57:30 2016 +0300 +++ b/Misc/NEWS Sat Jul 02 22:52:54 2016 +0300 @@ -10,6 +10,9 @@ What's New in Python 3.6.0 alpha 3 Core and Builtins ----------------- +- Issue #XXXXX: __length_hint__() of bytearray itearator no longer return + negative integer for resized bytearray. + - Issue #27007: The fromhex() class methods of bytes and bytearray subclasses now return an instance of corresponding subclass. diff -r b0087e17cd5e Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Fri Jul 01 17:57:30 2016 +0300 +++ b/Objects/bytearrayobject.c Sat Jul 02 22:52:54 2016 +0300 @@ -2248,8 +2248,12 @@ static PyObject * bytearrayiter_length_hint(bytesiterobject *it) { Py_ssize_t len = 0; - if (it->it_seq) + if (it->it_seq) { len = PyByteArray_GET_SIZE(it->it_seq) - it->it_index; + if (len < 0) { + len = 0; + } + } return PyLong_FromSsize_t(len); }