From e354ef7fc59fb21bfa7fcb0ec5822557cd535a11 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:04:41 +0900 Subject: [PATCH 01/22] add wurlitzer stubs. --fixup=ea82d69 --- stubs/wurlitzer/METADATA.toml | 7 +++++ stubs/wurlitzer/wurlitzer/__init__.pyi | 43 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 stubs/wurlitzer/METADATA.toml create mode 100644 stubs/wurlitzer/wurlitzer/__init__.pyi diff --git a/stubs/wurlitzer/METADATA.toml b/stubs/wurlitzer/METADATA.toml new file mode 100644 index 000000000000..da58a60fa511 --- /dev/null +++ b/stubs/wurlitzer/METADATA.toml @@ -0,0 +1,7 @@ +version = "3.0.*" +upstream_repository = "https://github.com/minrk/wurlitzer" +requires = ["ipython"] +partial_stub = true + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi new file mode 100644 index 000000000000..1c2be5008d58 --- /dev/null +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -0,0 +1,43 @@ +import contextlib +import io +from _typeshed import Incomplete +from collections.abc import Iterator +from contextlib import contextmanager +from types import TracebackType +from typing import Final, Literal, TextIO, TypeAlias + +from IPython.core.interactiveshell import InteractiveShell + +STDOUT: Final = 2 +PIPE: Final = 3 +_STDOUT: TypeAlias = Literal[2] +_PIPE: TypeAlias = Literal[3] + +class Wurlitzer: + flush_interval: float = 0.2 + + def __init__( + self, + stdout: TextIO | io.IOBase | None = None, + stderr: _STDOUT | TextIO | io.IOBase | None = None, + encoding: str = ..., + bufsize: int | None = ..., + ) -> None: ... + def __enter__(self): ... + def __exit__( + self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None + ) -> None: ... + +def dup2(a: int, b: int, timeout: int = 3) -> int: ... +def sys_pipes( + encoding: str = ..., bufsize: int | None = None +) -> contextlib._GeneratorContextManager[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... +@contextmanager +def pipes( + stdout: _PIPE | TextIO = 3, stderr: _STDOUT | _PIPE | TextIO = 3, encoding: str = ..., bufsize: int | None = None +) -> Iterator[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... +def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... +def stop_sys_pipes() -> None: ... +def load_ipython_extension(ip: InteractiveShell) -> None: ... +def unload_ipython_extension(ip: InteractiveShell) -> None: ... +def __getattr__(name: str) -> Incomplete: ... From 87129a1613fdb66cad423cee8485da2216c14521 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:09:05 +0900 Subject: [PATCH 02/22] add wurlitzer to pyright config. --- pyrightconfig.stricter.json | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 8579b6dd516b..7ae385c37db4 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -81,6 +81,7 @@ "stubs/vobject", "stubs/WebOb", "stubs/workalendar", + "stubs/wurlitzer", ], "typeCheckingMode": "strict", // TODO: Complete incomplete stubs From 1962932e7430ae161dea7f2f0e09909bdf560fef Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:13:22 +0900 Subject: [PATCH 03/22] add __all__ --- stubs/wurlitzer/wurlitzer/__init__.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index 1c2be5008d58..fef63b7f059d 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -41,3 +41,5 @@ def stop_sys_pipes() -> None: ... def load_ipython_extension(ip: InteractiveShell) -> None: ... def unload_ipython_extension(ip: InteractiveShell) -> None: ... def __getattr__(name: str) -> Incomplete: ... + +__all__ = ["STDOUT", "PIPE", "Wurlitzer", "pipes", "sys_pipes", "sys_pipes_forever", "stop_sys_pipes"] From 119c68e3eb1a0a35170fdf2d3d6cbd55f3c890d4 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:13:51 +0900 Subject: [PATCH 04/22] remove __getattr__ --- stubs/wurlitzer/wurlitzer/__init__.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index fef63b7f059d..508ebd4724ea 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -1,6 +1,5 @@ import contextlib import io -from _typeshed import Incomplete from collections.abc import Iterator from contextlib import contextmanager from types import TracebackType @@ -40,6 +39,5 @@ def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... def stop_sys_pipes() -> None: ... def load_ipython_extension(ip: InteractiveShell) -> None: ... def unload_ipython_extension(ip: InteractiveShell) -> None: ... -def __getattr__(name: str) -> Incomplete: ... __all__ = ["STDOUT", "PIPE", "Wurlitzer", "pipes", "sys_pipes", "sys_pipes_forever", "stop_sys_pipes"] From 4bf893158513907d39fc7e1c819ac96573554115 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:20:23 +0900 Subject: [PATCH 05/22] fix TypeAlias import --- stubs/wurlitzer/wurlitzer/__init__.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index 508ebd4724ea..43974bd2eea3 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -3,7 +3,8 @@ import io from collections.abc import Iterator from contextlib import contextmanager from types import TracebackType -from typing import Final, Literal, TextIO, TypeAlias +from typing import Final, Literal, TextIO +from typing_extensions import TypeAlias from IPython.core.interactiveshell import InteractiveShell From 8fd53d7bc655eaa14962093902d98e902a34e688 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:28:24 +0900 Subject: [PATCH 06/22] remove IPython dependency --- stubs/wurlitzer/METADATA.toml | 1 - stubs/wurlitzer/wurlitzer/__init__.pyi | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/stubs/wurlitzer/METADATA.toml b/stubs/wurlitzer/METADATA.toml index da58a60fa511..cd339b195bdc 100644 --- a/stubs/wurlitzer/METADATA.toml +++ b/stubs/wurlitzer/METADATA.toml @@ -1,6 +1,5 @@ version = "3.0.*" upstream_repository = "https://github.com/minrk/wurlitzer" -requires = ["ipython"] partial_stub = true [tool.stubtest] diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index 43974bd2eea3..c8a5fe415693 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -1,13 +1,12 @@ import contextlib import io +from _typeshed import Incomplete from collections.abc import Iterator from contextlib import contextmanager from types import TracebackType from typing import Final, Literal, TextIO from typing_extensions import TypeAlias -from IPython.core.interactiveshell import InteractiveShell - STDOUT: Final = 2 PIPE: Final = 3 _STDOUT: TypeAlias = Literal[2] @@ -38,7 +37,7 @@ def pipes( ) -> Iterator[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... def stop_sys_pipes() -> None: ... -def load_ipython_extension(ip: InteractiveShell) -> None: ... -def unload_ipython_extension(ip: InteractiveShell) -> None: ... +def load_ipython_extension(ip: Incomplete) -> None: ... # IPython.core.interactiveshell.InteractiveShell +def unload_ipython_extension(ip: Incomplete) -> None: ... # IPython.core.interactiveshell.InteractiveShell __all__ = ["STDOUT", "PIPE", "Wurlitzer", "pipes", "sys_pipes", "sys_pipes_forever", "stop_sys_pipes"] From 21be2e5743215fccee3fd6989da42ad7a68b288c Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:38:02 +0900 Subject: [PATCH 07/22] remove partial_stub --- stubs/wurlitzer/METADATA.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stubs/wurlitzer/METADATA.toml b/stubs/wurlitzer/METADATA.toml index cd339b195bdc..7e633c7caf21 100644 --- a/stubs/wurlitzer/METADATA.toml +++ b/stubs/wurlitzer/METADATA.toml @@ -1,6 +1,2 @@ version = "3.0.*" upstream_repository = "https://github.com/minrk/wurlitzer" -partial_stub = true - -[tool.stubtest] -ignore_missing_stub = false From d4049adca85a663c97d9470e60c30f32a7025634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:58:05 +0900 Subject: [PATCH 08/22] Update stubs/wurlitzer/wurlitzer/__init__.pyi Co-authored-by: Alex Waygood --- stubs/wurlitzer/wurlitzer/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index c8a5fe415693..99f4d33d5778 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -27,7 +27,7 @@ class Wurlitzer: self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None ) -> None: ... -def dup2(a: int, b: int, timeout: int = 3) -> int: ... +def dup2(a: int, b: int, timeout: float = 3) -> int: ... def sys_pipes( encoding: str = ..., bufsize: int | None = None ) -> contextlib._GeneratorContextManager[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... From 2b2131f5a93581d7eb85717f28fe68b160b0760e Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 21:59:26 +0900 Subject: [PATCH 09/22] add InteractiveShell alias --- stubs/wurlitzer/wurlitzer/__init__.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index 99f4d33d5778..98cb217f3a20 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -1,16 +1,16 @@ import contextlib import io -from _typeshed import Incomplete from collections.abc import Iterator from contextlib import contextmanager from types import TracebackType -from typing import Final, Literal, TextIO +from typing import Any, Final, Literal, TextIO from typing_extensions import TypeAlias STDOUT: Final = 2 PIPE: Final = 3 _STDOUT: TypeAlias = Literal[2] _PIPE: TypeAlias = Literal[3] +_InteractiveShell: TypeAlias = Any class Wurlitzer: flush_interval: float = 0.2 @@ -37,7 +37,7 @@ def pipes( ) -> Iterator[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... def stop_sys_pipes() -> None: ... -def load_ipython_extension(ip: Incomplete) -> None: ... # IPython.core.interactiveshell.InteractiveShell -def unload_ipython_extension(ip: Incomplete) -> None: ... # IPython.core.interactiveshell.InteractiveShell +def load_ipython_extension(ip: _InteractiveShell) -> None: ... +def unload_ipython_extension(ip: _InteractiveShell) -> None: ... __all__ = ["STDOUT", "PIPE", "Wurlitzer", "pipes", "sys_pipes", "sys_pipes_forever", "stop_sys_pipes"] From d3a8085f8c111653c8659dcc21f56f79a4199f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Wed, 21 Feb 2024 22:08:01 +0900 Subject: [PATCH 10/22] Update stubs/wurlitzer/wurlitzer/__init__.pyi Co-authored-by: Alex Waygood --- stubs/wurlitzer/wurlitzer/__init__.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer/__init__.pyi index 98cb217f3a20..b721a84ac67a 100644 --- a/stubs/wurlitzer/wurlitzer/__init__.pyi +++ b/stubs/wurlitzer/wurlitzer/__init__.pyi @@ -10,6 +10,11 @@ STDOUT: Final = 2 PIPE: Final = 3 _STDOUT: TypeAlias = Literal[2] _PIPE: TypeAlias = Literal[3] + +# Alias for IPython.core.interactiveshell.InteractiveShell. +# N.B. Even if we added ipython to the stub-uploader allowlist, +# we wouldn't be able to declare a dependency on ipython here, +# since `wurlitzer` does not declare a dependency on `ipython` at runtime _InteractiveShell: TypeAlias = Any class Wurlitzer: From 378b2d01f3b1738f2e873d74ff85daa3850ec77a Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 22:08:33 +0900 Subject: [PATCH 11/22] rename/move stub file --- stubs/wurlitzer/{wurlitzer/__init__.pyi => wurlitzer.pyi} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stubs/wurlitzer/{wurlitzer/__init__.pyi => wurlitzer.pyi} (100%) diff --git a/stubs/wurlitzer/wurlitzer/__init__.pyi b/stubs/wurlitzer/wurlitzer.pyi similarity index 100% rename from stubs/wurlitzer/wurlitzer/__init__.pyi rename to stubs/wurlitzer/wurlitzer.pyi From b29f75038c04a5cf186963e1eefacc698fb35910 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 22:16:20 +0900 Subject: [PATCH 12/22] use protocol for inputs --- stubs/wurlitzer/wurlitzer.pyi | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index b721a84ac67a..55627ae2b87e 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -1,5 +1,6 @@ import contextlib import io +from _typeshed import SupportsWrite from collections.abc import Iterator from contextlib import contextmanager from types import TracebackType @@ -22,8 +23,8 @@ class Wurlitzer: def __init__( self, - stdout: TextIO | io.IOBase | None = None, - stderr: _STDOUT | TextIO | io.IOBase | None = None, + stdout: SupportsWrite[str | bytes] | None = None, + stderr: _STDOUT | SupportsWrite[str | bytes] | None = None, encoding: str = ..., bufsize: int | None = ..., ) -> None: ... @@ -38,7 +39,10 @@ def sys_pipes( ) -> contextlib._GeneratorContextManager[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... @contextmanager def pipes( - stdout: _PIPE | TextIO = 3, stderr: _STDOUT | _PIPE | TextIO = 3, encoding: str = ..., bufsize: int | None = None + stdout: _PIPE | SupportsWrite[str | bytes] = 3, + stderr: _STDOUT | _PIPE | SupportsWrite[str | bytes] = 3, + encoding: str = ..., + bufsize: int | None = None, ) -> Iterator[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... def stop_sys_pipes() -> None: ... From 80f410c74621e1695078efa30163935e86f36949 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 21 Feb 2024 23:10:06 +0900 Subject: [PATCH 13/22] Improve protocol usage, add overloads for pipes. --- stubs/wurlitzer/wurlitzer.pyi | 58 ++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index 55627ae2b87e..5823171657eb 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -4,13 +4,19 @@ from _typeshed import SupportsWrite from collections.abc import Iterator from contextlib import contextmanager from types import TracebackType -from typing import Any, Final, Literal, TextIO +from typing import Any, Final, Literal, Protocol, TextIO, TypeVar, overload from typing_extensions import TypeAlias STDOUT: Final = 2 PIPE: Final = 3 _STDOUT: TypeAlias = Literal[2] _PIPE: TypeAlias = Literal[3] +_T_contra = TypeVar("_T_contra", contravariant=True) +_StreamOutT = TypeVar("_StreamOutT", bound=_Stream[str] | _Stream[bytes]) +_StreamErrT = TypeVar("_StreamErrT", bound=_Stream[str] | _Stream[bytes]) + +class _Stream(SupportsWrite[_T_contra], Protocol): + def seek(self, __offset: int, __whence: int = ...) -> int: ... # Alias for IPython.core.interactiveshell.InteractiveShell. # N.B. Even if we added ipython to the stub-uploader allowlist, @@ -23,9 +29,9 @@ class Wurlitzer: def __init__( self, - stdout: SupportsWrite[str | bytes] | None = None, - stderr: _STDOUT | SupportsWrite[str | bytes] | None = None, - encoding: str = ..., + stdout: _Stream[str] | _Stream[bytes] | None = None, + stderr: _STDOUT | _Stream[str] | _Stream[bytes] | None = None, + encoding: str | None = ..., bufsize: int | None = ..., ) -> None: ... def __enter__(self): ... @@ -34,16 +40,46 @@ class Wurlitzer: ) -> None: ... def dup2(a: int, b: int, timeout: float = 3) -> int: ... -def sys_pipes( - encoding: str = ..., bufsize: int | None = None -) -> contextlib._GeneratorContextManager[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... +def sys_pipes(encoding: str = ..., bufsize: int | None = None) -> contextlib._GeneratorContextManager[tuple[TextIO, TextIO]]: ... +@overload +@contextmanager +def pipes(stdout: _PIPE, stderr: _STDOUT, encoding: None, bufsize: int | None = None) -> Iterator[tuple[io.BytesIO, None]]: ... +@overload +@contextmanager +def pipes( + stdout: _PIPE, stderr: _PIPE, encoding: None, bufsize: int | None = None +) -> Iterator[tuple[io.BytesIO, io.BytesIO]]: ... +@overload +@contextmanager +def pipes( + stdout: _PIPE, stderr: _StreamErrT, encoding: None, bufsize: int | None = None +) -> Iterator[tuple[io.BytesIO, _StreamErrT]]: ... +@overload +@contextmanager +def pipes(stdout: _PIPE, stderr: _STDOUT, encoding: str, bufsize: int | None = None) -> Iterator[tuple[io.StringIO, None]]: ... +@overload +@contextmanager +def pipes( + stdout: _PIPE, stderr: _PIPE, encoding: str, bufsize: int | None = None +) -> Iterator[tuple[io.StringIO, io.StringIO]]: ... +@overload +@contextmanager +def pipes( + stdout: _PIPE, stderr: _StreamErrT, encoding: str, bufsize: int | None = None +) -> Iterator[tuple[io.StringIO, _StreamErrT]]: ... +@overload +@contextmanager +def pipes( + stdout: _StreamOutT, stderr: _StreamErrT, encoding: str | None, bufsize: int | None = None +) -> Iterator[tuple[_StreamOutT, _StreamErrT]]: ... +@overload @contextmanager def pipes( - stdout: _PIPE | SupportsWrite[str | bytes] = 3, - stderr: _STDOUT | _PIPE | SupportsWrite[str | bytes] = 3, - encoding: str = ..., + stdout: _PIPE | _StreamOutT = 3, + stderr: _STDOUT | _PIPE | _StreamErrT = 3, + encoding: str | None = ..., bufsize: int | None = None, -) -> Iterator[tuple[TextIO | io.BytesIO | io.StringIO, TextIO | io.BytesIO | io.StringIO | None]]: ... +) -> Iterator[tuple[io.BytesIO | io.StringIO | _StreamOutT, io.BytesIO | io.StringIO | _StreamErrT | None]]: ... def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... def stop_sys_pipes() -> None: ... def load_ipython_extension(ip: _InteractiveShell) -> None: ... From 63b2a4f120edc50fc67151d6ba87bae65d119d7c Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Thu, 22 Feb 2024 08:11:34 +0900 Subject: [PATCH 14/22] use _GeneratorContextManager instead of contextmanager, add missing overloads. --- stubs/wurlitzer/wurlitzer.pyi | 43 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index 5823171657eb..4c7856618144 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -1,8 +1,7 @@ import contextlib import io from _typeshed import SupportsWrite -from collections.abc import Iterator -from contextlib import contextmanager +from contextlib import _GeneratorContextManager from types import TracebackType from typing import Any, Final, Literal, Protocol, TextIO, TypeVar, overload from typing_extensions import TypeAlias @@ -42,44 +41,52 @@ class Wurlitzer: def dup2(a: int, b: int, timeout: float = 3) -> int: ... def sys_pipes(encoding: str = ..., bufsize: int | None = None) -> contextlib._GeneratorContextManager[tuple[TextIO, TextIO]]: ... @overload -@contextmanager -def pipes(stdout: _PIPE, stderr: _STDOUT, encoding: None, bufsize: int | None = None) -> Iterator[tuple[io.BytesIO, None]]: ... +def pipes( + stdout: _PIPE, stderr: _STDOUT, encoding: None, bufsize: int | None = None +) -> _GeneratorContextManager[tuple[io.BytesIO, None]]: ... @overload -@contextmanager def pipes( stdout: _PIPE, stderr: _PIPE, encoding: None, bufsize: int | None = None -) -> Iterator[tuple[io.BytesIO, io.BytesIO]]: ... +) -> _GeneratorContextManager[tuple[io.BytesIO, io.BytesIO]]: ... @overload -@contextmanager def pipes( stdout: _PIPE, stderr: _StreamErrT, encoding: None, bufsize: int | None = None -) -> Iterator[tuple[io.BytesIO, _StreamErrT]]: ... +) -> _GeneratorContextManager[tuple[io.BytesIO, _StreamErrT]]: ... @overload -@contextmanager -def pipes(stdout: _PIPE, stderr: _STDOUT, encoding: str, bufsize: int | None = None) -> Iterator[tuple[io.StringIO, None]]: ... +def pipes( + stdout: _PIPE, stderr: _STDOUT, encoding: str, bufsize: int | None = None +) -> _GeneratorContextManager[tuple[io.StringIO, None]]: ... @overload -@contextmanager def pipes( stdout: _PIPE, stderr: _PIPE, encoding: str, bufsize: int | None = None -) -> Iterator[tuple[io.StringIO, io.StringIO]]: ... +) -> _GeneratorContextManager[tuple[io.StringIO, io.StringIO]]: ... @overload -@contextmanager def pipes( stdout: _PIPE, stderr: _StreamErrT, encoding: str, bufsize: int | None = None -) -> Iterator[tuple[io.StringIO, _StreamErrT]]: ... +) -> _GeneratorContextManager[tuple[io.StringIO, _StreamErrT]]: ... +@overload +def pipes( + stdout: _StreamOutT, stderr: _STDOUT, encoding: str | None, bufsize: int | None = None +) -> _GeneratorContextManager[tuple[_StreamOutT, None]]: ... +@overload +def pipes( + stdout: _StreamOutT, stderr: _PIPE, encoding: None, bufsize: int | None = None +) -> _GeneratorContextManager[tuple[_StreamOutT, io.BytesIO]]: ... +@overload +def pipes( + stdout: _StreamOutT, stderr: _PIPE, encoding: str, bufsize: int | None = None +) -> _GeneratorContextManager[tuple[_StreamOutT, io.StringIO]]: ... @overload -@contextmanager def pipes( stdout: _StreamOutT, stderr: _StreamErrT, encoding: str | None, bufsize: int | None = None -) -> Iterator[tuple[_StreamOutT, _StreamErrT]]: ... +) -> _GeneratorContextManager[tuple[_StreamOutT, _StreamErrT]]: ... @overload -@contextmanager def pipes( stdout: _PIPE | _StreamOutT = 3, stderr: _STDOUT | _PIPE | _StreamErrT = 3, encoding: str | None = ..., bufsize: int | None = None, -) -> Iterator[tuple[io.BytesIO | io.StringIO | _StreamOutT, io.BytesIO | io.StringIO | _StreamErrT | None]]: ... +) -> _GeneratorContextManager[tuple[io.BytesIO | io.StringIO | _StreamOutT, io.BytesIO | io.StringIO | _StreamErrT | None]]: ... def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... def stop_sys_pipes() -> None: ... def load_ipython_extension(ip: _InteractiveShell) -> None: ... From ccf8f9dd14cb419303b79fc8fdb809c5dfc4308d Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Thu, 22 Feb 2024 08:22:39 +0900 Subject: [PATCH 15/22] add comment --- stubs/wurlitzer/wurlitzer.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index 4c7856618144..a6b67256ee21 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -40,6 +40,8 @@ class Wurlitzer: def dup2(a: int, b: int, timeout: float = 3) -> int: ... def sys_pipes(encoding: str = ..., bufsize: int | None = None) -> contextlib._GeneratorContextManager[tuple[TextIO, TextIO]]: ... + +# stubtest does not support overloaded context managers, hence the _GeneratorContextManager[Foo] return types. @overload def pipes( stdout: _PIPE, stderr: _STDOUT, encoding: None, bufsize: int | None = None From 0de10e2e5909f233866a8b4d76798d60b36ad4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:09:41 +0900 Subject: [PATCH 16/22] Update stubs/wurlitzer/wurlitzer.pyi Co-authored-by: Akuli --- stubs/wurlitzer/wurlitzer.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index a6b67256ee21..a010b3ea1d7a 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -24,7 +24,8 @@ class _Stream(SupportsWrite[_T_contra], Protocol): _InteractiveShell: TypeAlias = Any class Wurlitzer: - flush_interval: float = 0.2 + flush_interval: float + encoding: str | None def __init__( self, From aa5e91092070431d2e426bcf7d8506fe36fbd37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:12:19 +0900 Subject: [PATCH 17/22] Update stubs/wurlitzer/wurlitzer.pyi Co-authored-by: Akuli --- stubs/wurlitzer/wurlitzer.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index a010b3ea1d7a..e531fca62656 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -57,15 +57,15 @@ def pipes( ) -> _GeneratorContextManager[tuple[io.BytesIO, _StreamErrT]]: ... @overload def pipes( - stdout: _PIPE, stderr: _STDOUT, encoding: str, bufsize: int | None = None + stdout: _PIPE, stderr: _STDOUT, encoding: str = ..., bufsize: int | None = None ) -> _GeneratorContextManager[tuple[io.StringIO, None]]: ... @overload def pipes( - stdout: _PIPE, stderr: _PIPE, encoding: str, bufsize: int | None = None + stdout: _PIPE, stderr: _PIPE, encoding: str = ..., bufsize: int | None = None ) -> _GeneratorContextManager[tuple[io.StringIO, io.StringIO]]: ... @overload def pipes( - stdout: _PIPE, stderr: _StreamErrT, encoding: str, bufsize: int | None = None + stdout: _PIPE, stderr: _StreamErrT, encoding: str = ..., bufsize: int | None = None ) -> _GeneratorContextManager[tuple[io.StringIO, _StreamErrT]]: ... @overload def pipes( From 9a20f54a4015ab09c293a7e0eb445668cae098f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:12:25 +0900 Subject: [PATCH 18/22] Update stubs/wurlitzer/wurlitzer.pyi Co-authored-by: Akuli --- stubs/wurlitzer/wurlitzer.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index e531fca62656..226df80620af 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -29,8 +29,8 @@ class Wurlitzer: def __init__( self, - stdout: _Stream[str] | _Stream[bytes] | None = None, - stderr: _STDOUT | _Stream[str] | _Stream[bytes] | None = None, + stdout: SupportsWrite[str] | SupportsWrite[bytes] | None = None, + stderr: _STDOUT | SupportsWrite[str] | SupportsWrite[bytes] | None = None, encoding: str | None = ..., bufsize: int | None = ..., ) -> None: ... From 1b92732fe1f4776354a4271e1e56fe05dcadf486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:12:44 +0900 Subject: [PATCH 19/22] Update stubs/wurlitzer/wurlitzer.pyi Co-authored-by: Akuli --- stubs/wurlitzer/wurlitzer.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index 226df80620af..d3b9322900da 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -69,7 +69,7 @@ def pipes( ) -> _GeneratorContextManager[tuple[io.StringIO, _StreamErrT]]: ... @overload def pipes( - stdout: _StreamOutT, stderr: _STDOUT, encoding: str | None, bufsize: int | None = None + stdout: _StreamOutT, stderr: _STDOUT, encoding: str | None = ..., bufsize: int | None = None ) -> _GeneratorContextManager[tuple[_StreamOutT, None]]: ... @overload def pipes( From d67060b2f9de325e6a8a84747bd4858777c9f4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:12:58 +0900 Subject: [PATCH 20/22] Update stubs/wurlitzer/wurlitzer.pyi Co-authored-by: Akuli --- stubs/wurlitzer/wurlitzer.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index d3b9322900da..16f7f1d2552b 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -77,7 +77,7 @@ def pipes( ) -> _GeneratorContextManager[tuple[_StreamOutT, io.BytesIO]]: ... @overload def pipes( - stdout: _StreamOutT, stderr: _PIPE, encoding: str, bufsize: int | None = None + stdout: _StreamOutT, stderr: _PIPE, encoding: str = ..., bufsize: int | None = None ) -> _GeneratorContextManager[tuple[_StreamOutT, io.StringIO]]: ... @overload def pipes( From 9d7562bb2ae7cdd4c719feeb4c9d634d086426bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:13:24 +0900 Subject: [PATCH 21/22] Apply suggestions from code review Co-authored-by: Akuli --- stubs/wurlitzer/wurlitzer.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index 16f7f1d2552b..dea862a1a56e 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -81,7 +81,7 @@ def pipes( ) -> _GeneratorContextManager[tuple[_StreamOutT, io.StringIO]]: ... @overload def pipes( - stdout: _StreamOutT, stderr: _StreamErrT, encoding: str | None, bufsize: int | None = None + stdout: _StreamOutT, stderr: _StreamErrT, encoding: str | None = ..., bufsize: int | None = None ) -> _GeneratorContextManager[tuple[_StreamOutT, _StreamErrT]]: ... @overload def pipes( @@ -90,7 +90,7 @@ def pipes( encoding: str | None = ..., bufsize: int | None = None, ) -> _GeneratorContextManager[tuple[io.BytesIO | io.StringIO | _StreamOutT, io.BytesIO | io.StringIO | _StreamErrT | None]]: ... -def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None): ... +def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None) -> None: ... def stop_sys_pipes() -> None: ... def load_ipython_extension(ip: _InteractiveShell) -> None: ... def unload_ipython_extension(ip: _InteractiveShell) -> None: ... From c34be49e477b4575ec0efdbfe71e54f1f4bfcc27 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Sat, 9 Mar 2024 20:15:05 +0900 Subject: [PATCH 22/22] place __all__ at the top of the file. --- stubs/wurlitzer/wurlitzer.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/wurlitzer/wurlitzer.pyi b/stubs/wurlitzer/wurlitzer.pyi index dea862a1a56e..f2b1c7fa5a01 100644 --- a/stubs/wurlitzer/wurlitzer.pyi +++ b/stubs/wurlitzer/wurlitzer.pyi @@ -1,3 +1,5 @@ +__all__ = ["STDOUT", "PIPE", "Wurlitzer", "pipes", "sys_pipes", "sys_pipes_forever", "stop_sys_pipes"] + import contextlib import io from _typeshed import SupportsWrite @@ -94,5 +96,3 @@ def sys_pipes_forever(encoding: str = ..., bufsize: int | None = None) -> None: def stop_sys_pipes() -> None: ... def load_ipython_extension(ip: _InteractiveShell) -> None: ... def unload_ipython_extension(ip: _InteractiveShell) -> None: ... - -__all__ = ["STDOUT", "PIPE", "Wurlitzer", "pipes", "sys_pipes", "sys_pipes_forever", "stop_sys_pipes"]