diff options
author | Sebastian Rittau <srittau@rittau.biz> | 2025-03-06 15:36:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-06 15:36:19 (GMT) |
commit | c6dd2348ca61436fc1444ecc0343cb24932f6fa7 (patch) | |
tree | 549d12e443ddcdd38425e26ac8896b8ab5780006 /Lib/test/test_io.py | |
parent | 9c691500f9412ecd8f6221c20984dc7a55a8a9e8 (diff) | |
download | cpython-c6dd2348ca61436fc1444ecc0343cb24932f6fa7.zip cpython-c6dd2348ca61436fc1444ecc0343cb24932f6fa7.tar.gz cpython-c6dd2348ca61436fc1444ecc0343cb24932f6fa7.tar.bz2 |
gh-127647: Add typing.Reader and Writer protocols (#127648)
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index e59d397..3b8ff1d 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -4916,6 +4916,24 @@ class PySignalsTest(SignalsTest): test_reentrant_write_text = None +class ProtocolsTest(unittest.TestCase): + class MyReader: + def read(self, sz=-1): + return b"" + + class MyWriter: + def write(self, b: bytes): + pass + + def test_reader_subclass(self): + self.assertIsSubclass(MyReader, io.Reader[bytes]) + self.assertNotIsSubclass(str, io.Reader[bytes]) + + def test_writer_subclass(self): + self.assertIsSubclass(MyWriter, io.Writer[bytes]) + self.assertNotIsSubclass(str, io.Writer[bytes]) + + def load_tests(loader, tests, pattern): tests = (CIOTest, PyIOTest, APIMismatchTest, CBufferedReaderTest, PyBufferedReaderTest, |