mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-38785: Prevent asyncio from crashing (GH-17144)
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future` https://bugs.python.org/issue38785
This commit is contained in:
parent
61289d4366
commit
dad6be5ffe
4 changed files with 46 additions and 1 deletions
|
@ -822,5 +822,44 @@ class PyFutureDoneCallbackTests(BaseFutureDoneCallbackTests,
|
|||
return futures._PyFuture(loop=self.loop)
|
||||
|
||||
|
||||
class BaseFutureInheritanceTests:
|
||||
|
||||
def _get_future_cls(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.loop = self.new_test_loop()
|
||||
self.addCleanup(self.loop.close)
|
||||
|
||||
def test_inherit_without_calling_super_init(self):
|
||||
# See https://bugs.python.org/issue38785 for the context
|
||||
cls = self._get_future_cls()
|
||||
|
||||
class MyFut(cls):
|
||||
def __init__(self, *args, **kwargs):
|
||||
# don't call super().__init__()
|
||||
pass
|
||||
|
||||
fut = MyFut(loop=self.loop)
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError,
|
||||
"Future object is not initialized."
|
||||
):
|
||||
fut.get_loop()
|
||||
|
||||
|
||||
class PyFutureInheritanceTests(BaseFutureInheritanceTests,
|
||||
test_utils.TestCase):
|
||||
def _get_future_cls(self):
|
||||
return futures._PyFuture
|
||||
|
||||
|
||||
class CFutureInheritanceTests(BaseFutureInheritanceTests,
|
||||
test_utils.TestCase):
|
||||
def _get_future_cls(self):
|
||||
return futures._CFuture
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue