[Python-checkins] Replace deprecation warning with RuntimeError (GH-14397)

Miss Islington (bot) webhook-mailer at python.org
Thu Jun 27 07:58:39 EDT 2019


https://github.com/python/cpython/commit/4cbe7a3ce4a46a5a2f3e56055a665e583fead62d
commit: 4cbe7a3ce4a46a5a2f3e56055a665e583fead62d
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-27T04:58:34-07:00
summary:

Replace deprecation warning with RuntimeError (GH-14397)

(cherry picked from commit 97d15b1ee06ce80c4dbda91fb538a89bbcb2bed9)

Co-authored-by: Andrew Svetlov <andrew.svetlov at gmail.com>

files:
M Lib/asyncio/streams.py
M Lib/test/test_asyncio/test_streams.py

diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index f03441b6b11d..204eaf7394c5 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -1293,10 +1293,8 @@ def __init__(self, mode, *,
                  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 a1c62ecee662..eab71e80308f 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -1779,6 +1779,12 @@ def test_write_pipe(self):
 
         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()



More information about the Python-checkins mailing list