mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
bpo-12022: Change error type for bad objects in "with" and "async with" (GH-26809)
A TypeError is now raised instead of an AttributeError in "with" and "async with" statements for objects which do not support the context manager or asynchronous context manager protocols correspondingly.
This commit is contained in:
parent
48e3a1d95a
commit
20a88004ba
6 changed files with 48 additions and 26 deletions
|
@ -1212,7 +1212,7 @@ class CoroutineTest(unittest.TestCase):
|
|||
async with CM():
|
||||
body_executed = True
|
||||
|
||||
with self.assertRaisesRegex(AttributeError, '__aexit__'):
|
||||
with self.assertRaisesRegex(TypeError, 'asynchronous context manager.*__aexit__'):
|
||||
run_async(foo())
|
||||
self.assertIs(body_executed, False)
|
||||
|
||||
|
@ -1228,7 +1228,7 @@ class CoroutineTest(unittest.TestCase):
|
|||
async with CM():
|
||||
body_executed = True
|
||||
|
||||
with self.assertRaisesRegex(AttributeError, '__aenter__'):
|
||||
with self.assertRaisesRegex(TypeError, 'asynchronous context manager'):
|
||||
run_async(foo())
|
||||
self.assertIs(body_executed, False)
|
||||
|
||||
|
@ -1243,7 +1243,7 @@ class CoroutineTest(unittest.TestCase):
|
|||
async with CM():
|
||||
body_executed = True
|
||||
|
||||
with self.assertRaisesRegex(AttributeError, '__aenter__'):
|
||||
with self.assertRaisesRegex(TypeError, 'asynchronous context manager'):
|
||||
run_async(foo())
|
||||
self.assertIs(body_executed, False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue