]> granicus.if.org Git - python/commitdiff
Replace deprecation warning with RuntimeError (GH-14397)
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Thu, 27 Jun 2019 11:38:47 +0000 (14:38 +0300)
committerGitHub <noreply@github.com>
Thu, 27 Jun 2019 11:38:47 +0000 (14:38 +0300)
Lib/asyncio/streams.py
Lib/test/test_asyncio/test_streams.py

index f03441b6b11ded77d5976fc859294c75881a5112..204eaf7394c5bbb71d58eb2f7001a2e9c49b945b 100644 (file)
@@ -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
index a1c62ecee662b3de315d87d0ae232ff308f33164..eab71e80308fefc20469c3c5c87d66c4b332fb63 100644 (file)
@@ -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()