mirror of
https://github.com/python/cpython.git
synced 2025-10-05 22:51:56 +00:00
bpo-28893: Set __cause__ for errors in async iteration protocol (#407)
This commit is contained in:
parent
01e5230ef0
commit
dea5101ae1
3 changed files with 44 additions and 3 deletions
|
@ -1680,6 +1680,44 @@ class CoroutineTest(unittest.TestCase):
|
|||
warnings.simplefilter("error")
|
||||
run_async(foo())
|
||||
|
||||
def test_for_11(self):
|
||||
class F:
|
||||
def __aiter__(self):
|
||||
return self
|
||||
def __anext__(self):
|
||||
return self
|
||||
def __await__(self):
|
||||
1 / 0
|
||||
|
||||
async def main():
|
||||
async for _ in F():
|
||||
pass
|
||||
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'an invalid object from __anext__') as c:
|
||||
main().send(None)
|
||||
|
||||
err = c.exception
|
||||
self.assertIsInstance(err.__cause__, ZeroDivisionError)
|
||||
|
||||
def test_for_12(self):
|
||||
class F:
|
||||
def __aiter__(self):
|
||||
return self
|
||||
def __await__(self):
|
||||
1 / 0
|
||||
|
||||
async def main():
|
||||
async for _ in F():
|
||||
pass
|
||||
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'an invalid object from __aiter__') as c:
|
||||
main().send(None)
|
||||
|
||||
err = c.exception
|
||||
self.assertIsInstance(err.__cause__, ZeroDivisionError)
|
||||
|
||||
def test_for_tuple(self):
|
||||
class Done(Exception): pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue