mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Validate that __length_hint__ returns a usable result.
This commit is contained in:
parent
94a45da6be
commit
5d65412d35
2 changed files with 11 additions and 1 deletions
|
@ -208,6 +208,11 @@ class BadLengthHint(object):
|
|||
def __length_hint__(self):
|
||||
raise RuntimeError('hello')
|
||||
|
||||
class NoneLengthHint(object):
|
||||
def __iter__(self): return iter(range(10))
|
||||
def __length_hint__(self):
|
||||
return None
|
||||
|
||||
class TestLengthHintExceptions(unittest.TestCase):
|
||||
|
||||
def test_issue1242657(self):
|
||||
|
@ -219,6 +224,11 @@ class TestLengthHintExceptions(unittest.TestCase):
|
|||
self.assertRaises(RuntimeError, b.extend, BadLen())
|
||||
self.assertRaises(RuntimeError, b.extend, BadLengthHint())
|
||||
|
||||
def test_invalid_hint(self):
|
||||
# Make sure an invalid result doesn't muck-up the works
|
||||
self.assertEqual(list(NoneLengthHint()), list(range(10)))
|
||||
|
||||
|
||||
def test_main():
|
||||
unittests = [
|
||||
TestRepeat,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue