From fdea09f10d126904833ba128d93bd0a4a4815a60 Mon Sep 17 00:00:00 2001 From: Vegard Stikbakke Date: Thu, 30 Apr 2020 08:31:32 +0200 Subject: [PATCH 1/4] typing: Add peek method to BinaryIO --- stdlib/3/typing.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 6c4dcc25302e..e8e1d5632733 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -506,7 +506,6 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): class BinaryIO(IO[bytes]): # TODO readinto # TODO read1? - # TODO peek? @overload @abstractmethod def write(self, s: bytearray) -> int: ... @@ -514,6 +513,9 @@ class BinaryIO(IO[bytes]): @abstractmethod def write(self, s: bytes) -> int: ... + @abstractmethod + def peek(self, size: int = ...) -> bytes: ... + @abstractmethod def __enter__(self) -> BinaryIO: ... From f18ff3a07524c23e357081ab15e243cb99f7e086 Mon Sep 17 00:00:00 2001 From: Vegard Stikbakke Date: Thu, 30 Apr 2020 08:54:17 +0200 Subject: [PATCH 2/4] Make peek non-abstract --- stdlib/3/typing.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index e8e1d5632733..54fb1deb8a9d 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -506,6 +506,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): class BinaryIO(IO[bytes]): # TODO readinto # TODO read1? + def peek(self, size: int = ...) -> bytes: ... @overload @abstractmethod def write(self, s: bytearray) -> int: ... @@ -513,9 +514,6 @@ class BinaryIO(IO[bytes]): @abstractmethod def write(self, s: bytes) -> int: ... - @abstractmethod - def peek(self, size: int = ...) -> bytes: ... - @abstractmethod def __enter__(self) -> BinaryIO: ... From e3d06b21d46c6d4180c8c8c8a79063172945f114 Mon Sep 17 00:00:00 2001 From: Vegard Stikbakke Date: Thu, 30 Apr 2020 09:32:02 +0200 Subject: [PATCH 3/4] Change size to n --- stdlib/3/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 54fb1deb8a9d..930d76213a00 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -506,7 +506,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): class BinaryIO(IO[bytes]): # TODO readinto # TODO read1? - def peek(self, size: int = ...) -> bytes: ... + def peek(self, n: int = ...) -> bytes: ... @overload @abstractmethod def write(self, s: bytearray) -> int: ... From dd5e5e36df41c7062da5fc9999ebb96373d7c34a Mon Sep 17 00:00:00 2001 From: Vegard Stikbakke Date: Thu, 30 Apr 2020 09:37:47 +0200 Subject: [PATCH 4/4] Add method to whitelists --- tests/stubtest_whitelists/py35.txt | 1 + tests/stubtest_whitelists/py36.txt | 1 + tests/stubtest_whitelists/py37.txt | 1 + tests/stubtest_whitelists/py38.txt | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/stubtest_whitelists/py35.txt b/tests/stubtest_whitelists/py35.txt index 4a5b6e5758d2..a0a3ed36c391 100644 --- a/tests/stubtest_whitelists/py35.txt +++ b/tests/stubtest_whitelists/py35.txt @@ -53,6 +53,7 @@ sre_compile.dis subprocess.check_output tracemalloc.Filter.__init__ typing.AbstractSet.isdisjoint +typing.BinaryIO.peek typing.Coroutine.cr_await typing.Coroutine.cr_code typing.Coroutine.cr_frame diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index a80097857f90..4788afc09f61 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -53,6 +53,7 @@ typing.AsyncGenerator.ag_await typing.AsyncGenerator.ag_code typing.AsyncGenerator.ag_frame typing.AsyncGenerator.ag_running +typing.BinaryIO.peek typing.Coroutine.cr_await typing.Coroutine.cr_code typing.Coroutine.cr_frame diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index 3da982868a7b..725c48b6bf40 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -64,6 +64,7 @@ tracemalloc.Traceback.format types.ClassMethodDescriptorType.__get__ types.MethodDescriptorType.__get__ types.WrapperDescriptorType.__get__ +typing.BinaryIO.peek typing.runtime_checkable unittest.async_case urllib.parse.parse_qs diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index 7dd11a8e50cb..fb07ebd9f070 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -146,6 +146,7 @@ types.ClassMethodDescriptorType.__get__ types.CodeType.replace types.MethodDescriptorType.__get__ types.WrapperDescriptorType.__get__ +typing.BinaryIO.peek unittest.TestCase.addCleanup unittest.case.TestCase.addCleanup unittest.doModuleCleanups