mirror of
https://github.com/python/cpython.git
synced 2025-10-13 18:33:34 +00:00
GH-98363: Fix exception handling in batched() (GH-98523)
This commit is contained in:
parent
ec1f6f5f13
commit
a5ff80c8bc
2 changed files with 36 additions and 8 deletions
|
@ -2012,6 +2012,20 @@ class E:
|
|||
def __next__(self):
|
||||
3 // 0
|
||||
|
||||
class E2:
|
||||
'Test propagation of exceptions after two iterations'
|
||||
def __init__(self, seqn):
|
||||
self.seqn = seqn
|
||||
self.i = 0
|
||||
def __iter__(self):
|
||||
return self
|
||||
def __next__(self):
|
||||
if self.i == 2:
|
||||
raise ZeroDivisionError
|
||||
v = self.seqn[self.i]
|
||||
self.i += 1
|
||||
return v
|
||||
|
||||
class S:
|
||||
'Test immediate stop'
|
||||
def __init__(self, seqn):
|
||||
|
@ -2050,6 +2064,7 @@ class TestVariousIteratorArgs(unittest.TestCase):
|
|||
self.assertRaises(TypeError, batched, X(s), 2)
|
||||
self.assertRaises(TypeError, batched, N(s), 2)
|
||||
self.assertRaises(ZeroDivisionError, list, batched(E(s), 2))
|
||||
self.assertRaises(ZeroDivisionError, list, batched(E2(s), 4))
|
||||
|
||||
def test_chain(self):
|
||||
for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue