From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 27 Jun 2019 11:58:34 +0000 (-0700) Subject: Replace deprecation warning with RuntimeError (GH-14397) X-Git-Tag: v3.8.0b2~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cbe7a3ce4a46a5a2f3e56055a665e583fead62d;p=python Replace deprecation warning with RuntimeError (GH-14397) (cherry picked from commit 97d15b1ee06ce80c4dbda91fb538a89bbcb2bed9) Co-authored-by: Andrew Svetlov --- diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index f03441b6b1..204eaf7394 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -1293,10 +1293,8 @@ class Stream: is_server_side=False, _asyncio_internal=False): if not _asyncio_internal: - warnings.warn(f"{self.__class__} should be instaniated " - "by asyncio internals only, " - "please avoid its creation from user code", - DeprecationWarning) + raise RuntimeError(f"{self.__class__} should be instantiated " + "by asyncio internals only") self._mode = mode self._transport = transport self._protocol = protocol diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index a1c62ecee6..eab71e8030 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1779,6 +1779,12 @@ os.close(fd) self.loop.run_until_complete(test()) + def test_stream_ctor_forbidden(self): + with self.assertRaisesRegex(RuntimeError, + "should be instantiated " + "by asyncio internals only"): + asyncio.Stream(asyncio.StreamMode.READWRITE) + if __name__ == '__main__': unittest.main()