Skip to content

Commit 97d15b1

Browse files
authored
Replace deprecation warning with RuntimeError (GH-14397)
1 parent 667eaff commit 97d15b1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/asyncio/streams.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,8 @@ def __init__(self, mode, *,
12931293
is_server_side=False,
12941294
_asyncio_internal=False):
12951295
if not _asyncio_internal:
1296-
warnings.warn(f"{self.__class__} should be instaniated "
1297-
"by asyncio internals only, "
1298-
"please avoid its creation from user code",
1299-
DeprecationWarning)
1296+
raise RuntimeError(f"{self.__class__} should be instantiated "
1297+
"by asyncio internals only")
13001298
self._mode = mode
13011299
self._transport = transport
13021300
self._protocol = protocol

Lib/test/test_asyncio/test_streams.py

+6
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,12 @@ async def test():
17791779

17801780
self.loop.run_until_complete(test())
17811781

1782+
def test_stream_ctor_forbidden(self):
1783+
with self.assertRaisesRegex(RuntimeError,
1784+
"should be instantiated "
1785+
"by asyncio internals only"):
1786+
asyncio.Stream(asyncio.StreamMode.READWRITE)
1787+
17821788

17831789
if __name__ == '__main__':
17841790
unittest.main()

0 commit comments

Comments
 (0)