Skip to content

Commit

Permalink
Merge pull request #51 from python-trio/tjstum/subprocess_optional
Browse files Browse the repository at this point in the history
Mark many subprocess types as Optional
  • Loading branch information
oremanj authored Dec 16, 2021
2 parents 9158056 + 449080d commit aed1e7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 15 additions & 15 deletions trio-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ if sys.platform == "win32":
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: StrOrBytesPath = ...,
env: Mapping[str, str] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
startupinfo: subprocess.STARTUPINFO = ...,
creationflags: int = ...,
) -> Process: ...
Expand All @@ -722,13 +722,13 @@ if sys.platform == "win32":
capture_stdout: bool = ...,
capture_stderr: bool = ...,
check: bool = ...,
deliver_cancel: Callable[[Process], Awaitable[None]] = ...,
deliver_cancel: Optional[Callable[[Process], Awaitable[None]]] = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: StrOrBytesPath = ...,
env: Mapping[str, str] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
startupinfo: subprocess.STARTUPINFO = ...,
creationflags: int = ...,
) -> subprocess.CompletedProcess[bytes]: ...
Expand All @@ -743,8 +743,8 @@ else:
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: Literal[True],
cwd: StrOrBytesPath = ...,
env: Mapping[str, str] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
Expand All @@ -759,8 +759,8 @@ else:
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: StrOrBytesPath = ...,
env: Mapping[str, str] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
Expand All @@ -774,13 +774,13 @@ else:
capture_stdout: bool = ...,
capture_stderr: bool = ...,
check: bool = ...,
deliver_cancel: Callable[[Process], Awaitable[None]] = ...,
deliver_cancel: Optional[Callable[[Process], Awaitable[None]]] = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: Literal[True],
cwd: StrOrBytesPath = ...,
env: Mapping[str, str] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
Expand All @@ -794,13 +794,13 @@ else:
capture_stdout: bool = ...,
capture_stderr: bool = ...,
check: bool = ...,
deliver_cancel: Callable[[Process], Awaitable[None]] = ...,
deliver_cancel: Optional[Callable[[Process], Awaitable[None]]] = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: StrOrBytesPath = ...,
env: Mapping[str, str] = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
Expand Down
6 changes: 6 additions & 0 deletions trio_typing/_tests/test-data/trio-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,9 @@ async def test() -> None:
await trio.run_process(["cat", Path("/dev/null"), b"/dev/null"])
await trio.run_process(["cat", Path("/dev/null")], cwd=Path("/"))
await trio.run_process("cat /dev/null", shell=True)

[case testOptionalCwd]
import trio
async def test(_cwd=None) -> None:
await trio.run_process(["cat", "dev/null"], cwd="/")
await trio.run_process(["cat", "/dev/null"], cwd=_cwd)

0 comments on commit aed1e7d

Please sign in to comment.