Skip to content

subprocess: Backport typeshed typings #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions src/libvcs/_internal/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import dataclasses
import subprocess
import sys
from collections.abc import Mapping, Sequence
from collections.abc import Collection, Mapping, Sequence
from typing import (
IO,
TYPE_CHECKING,
Expand All @@ -60,6 +60,7 @@
from .dataclasses import SkipDefaultFieldsReprMixin

if TYPE_CHECKING:
from _typeshed import ReadableBuffer
from typing_extensions import TypeAlias


Expand All @@ -79,7 +80,7 @@ def __init__(self, output: str, *args: object) -> None:
Mapping[str, StrOrBytesPath],
]
_FILE: "TypeAlias" = Union[None, int, IO[Any]]
_TXT: "TypeAlias" = Union[bytes, str]
_InputString: "TypeAlias" = Union["ReadableBuffer", str]
#: Command
_CMD: "TypeAlias" = Union[StrOrBytesPath, Sequence[StrOrBytesPath]]

Expand Down Expand Up @@ -197,7 +198,7 @@ class SubprocessCommand(SkipDefaultFieldsReprMixin):
# POSIX-only
restore_signals: bool = True
start_new_session: bool = False
pass_fds: Any = ()
pass_fds: Collection[int] = ()
umask: int = -1
if sys.version_info >= (3, 10):
pipesize: int = -1
Expand All @@ -219,7 +220,7 @@ class SubprocessCommand(SkipDefaultFieldsReprMixin):
def Popen(
self,
args: Optional[_CMD] = ...,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = False,
*,
text: Optional[bool] = ...,
encoding: str,
Expand All @@ -230,7 +231,7 @@ def Popen(
def Popen(
self,
args: Optional[_CMD] = ...,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = False,
*,
text: Optional[bool] = ...,
encoding: Optional[str] = ...,
Expand All @@ -253,7 +254,7 @@ def Popen(
def Popen(
self,
args: Optional[_CMD] = ...,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = False,
*,
text: Literal[True],
encoding: Optional[str] = ...,
Expand All @@ -264,11 +265,11 @@ def Popen(
def Popen(
self,
args: Optional[_CMD] = ...,
universal_newlines: Literal[False] = ...,
universal_newlines: Optional[Literal[False]] = False,
*,
text: Literal[None, False] = ...,
encoding: None = ...,
errors: None = ...,
encoding: None = None,
errors: None = None,
) -> subprocess.Popen[bytes]: ...

def Popen(
Expand Down Expand Up @@ -325,7 +326,7 @@ def check_call(self, **kwargs: Any) -> int:
@overload
def check_output(
self,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = ...,
*,
input: Optional[Union[str, bytes]] = ...,
encoding: Optional[str] = ...,
Expand All @@ -349,7 +350,7 @@ def check_output(
@overload
def check_output(
self,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = ...,
*,
input: Optional[Union[str, bytes]] = ...,
encoding: Optional[str] = ...,
Expand All @@ -373,11 +374,11 @@ def check_output(
@overload
def check_output(
self,
universal_newlines: Literal[False],
universal_newlines: Optional[Literal[False]],
*,
input: Optional[Union[str, bytes]] = ...,
encoding: None = ...,
errors: None = ...,
encoding: None = None,
errors: None = None,
text: Literal[None, False] = ...,
**kwargs: Any,
) -> bytes: ...
Expand Down Expand Up @@ -432,39 +433,39 @@ def check_output(
@overload
def run(
self,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = ...,
*,
capture_output: bool = ...,
check: bool = ...,
capture_output: bool = False,
check: bool = False,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
input: Optional[str] = ...,
input: Optional["_InputString"] = None,
text: Literal[True],
) -> subprocess.CompletedProcess[str]: ...

@overload
def run(
self,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = ...,
*,
capture_output: bool = ...,
check: bool = ...,
capture_output: bool = False,
check: bool = False,
encoding: str,
errors: Optional[str] = ...,
input: Optional[str] = ...,
input: Optional["_InputString"] = None,
text: Optional[bool] = ...,
) -> subprocess.CompletedProcess[str]: ...

@overload
def run(
self,
universal_newlines: bool = ...,
universal_newlines: Optional[bool] = ...,
*,
capture_output: bool = ...,
check: bool = ...,
capture_output: bool = False,
check: bool = False,
encoding: Optional[str] = ...,
errors: str,
input: Optional[str] = ...,
input: Optional["_InputString"] = None,
text: Optional[bool] = ...,
) -> subprocess.CompletedProcess[str]: ...

Expand All @@ -474,24 +475,24 @@ def run(
*,
universal_newlines: Literal[True],
# where the *real* keyword only args start
capture_output: bool = ...,
check: bool = ...,
capture_output: bool = False,
check: bool = False,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
input: Optional[str] = ...,
input: Optional["_InputString"] = None,
text: Optional[bool] = ...,
) -> subprocess.CompletedProcess[str]: ...

@overload
def run(
self,
universal_newlines: Literal[False] = ...,
universal_newlines: Optional[Literal[False]] = ...,
*,
capture_output: bool = ...,
check: bool = ...,
encoding: None = ...,
errors: None = ...,
input: Optional[bytes] = ...,
capture_output: bool = False,
check: bool = False,
encoding: None = None,
errors: None = None,
input: Optional["ReadableBuffer"] = None,
text: Literal[None, False] = ...,
) -> subprocess.CompletedProcess[bytes]: ...

Expand All @@ -503,7 +504,7 @@ def run(
check: bool = False,
encoding: Optional[str] = None,
errors: Optional[str] = None,
input: Optional[Union[str, bytes]] = None,
input: Optional[Union["_InputString", "ReadableBuffer"]] = None,
text: Optional[bool] = None,
timeout: Optional[float] = None,
**kwargs: Any,
Expand Down