summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-11-13 21:54:56 (GMT)
committerGitHub <noreply@github.com>2019-11-13 21:54:56 (GMT)
commit694c03fabb5cf3df0102cc317670a10fc39c6786 (patch)
tree9fce2560ca025bae0ac72c0074944198bc06fcc8 /Lib/test/test_asyncio
parenta67bc10e42fa9a077eb4d9d7bd767c3efddbc366 (diff)
downloadcpython-694c03fabb5cf3df0102cc317670a10fc39c6786.zip
cpython-694c03fabb5cf3df0102cc317670a10fc39c6786.tar.gz
cpython-694c03fabb5cf3df0102cc317670a10fc39c6786.tar.bz2
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 (cherry picked from commit dad6be5ffe48beb74fad78cf758b886afddc7aed) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_futures.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index 2e4583d..ee5edd5 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -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()