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

Andrew Svetlov webhook-mailer at python.org
Thu Jun 27 07:38:51 EDT 2019


https://github.com/python/cpython/commit/97d15b1ee06ce80c4dbda91fb538a89bbcb2bed9
commit: 97d15b1ee06ce80c4dbda91fb538a89bbcb2bed9
branch: master
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-06-27T14:38:47+03:00
summary:

Replace deprecation warning with RuntimeError (GH-14397)

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