Skip to content

Commit 2d7e190

Browse files
authored
Merge pull request #10344 from jdufresne/on-return-code
Precise type of on_returncode argument to call_subprocess()
2 parents 618f7e7 + 3991bbc commit 2d7e190

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

news/e9465d48-04e5-4e3e-aa4a-450fc0f34a9e.trivial.rst

Whitespace-only changes.

src/pip/_internal/utils/subprocess.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
import os
33
import shlex
44
import subprocess
5-
from typing import Any, Callable, Iterable, List, Mapping, Optional, Union
5+
from typing import (
6+
TYPE_CHECKING,
7+
Any,
8+
Callable,
9+
Iterable,
10+
List,
11+
Mapping,
12+
Optional,
13+
Union,
14+
)
615

716
from pip._internal.cli.spinners import SpinnerInterface, open_spinner
817
from pip._internal.exceptions import InstallationSubprocessError
918
from pip._internal.utils.logging import VERBOSE, subprocess_logger
1019
from pip._internal.utils.misc import HiddenText
1120

21+
if TYPE_CHECKING:
22+
# Literal was introduced in Python 3.8.
23+
#
24+
# TODO: Remove `if TYPE_CHECKING` when dropping support for Python 3.7.
25+
from typing import Literal
26+
1227
CommandArgs = List[Union[str, HiddenText]]
1328

1429

@@ -97,7 +112,7 @@ def call_subprocess(
97112
cmd, # type: Union[List[str], CommandArgs]
98113
show_stdout=False, # type: bool
99114
cwd=None, # type: Optional[str]
100-
on_returncode="raise", # type: str
115+
on_returncode="raise", # type: Literal["raise", "warn", "ignore"]
101116
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
102117
command_desc=None, # type: Optional[str]
103118
extra_environ=None, # type: Optional[Mapping[str, Any]]

src/pip/_internal/vcs/versioncontrol.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import urllib.parse
88
from typing import (
9+
TYPE_CHECKING,
910
Any,
1011
Dict,
1112
Iterable,
@@ -33,6 +34,13 @@
3334
from pip._internal.utils.subprocess import CommandArgs, call_subprocess, make_command
3435
from pip._internal.utils.urls import get_url_scheme
3536

37+
if TYPE_CHECKING:
38+
# Literal was introduced in Python 3.8.
39+
#
40+
# TODO: Remove `if TYPE_CHECKING` when dropping support for Python 3.7.
41+
from typing import Literal
42+
43+
3644
__all__ = ['vcs']
3745

3846

@@ -650,7 +658,7 @@ def run_command(
650658
cmd, # type: Union[List[str], CommandArgs]
651659
show_stdout=True, # type: bool
652660
cwd=None, # type: Optional[str]
653-
on_returncode='raise', # type: str
661+
on_returncode='raise', # type: Literal["raise", "warn", "ignore"]
654662
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
655663
command_desc=None, # type: Optional[str]
656664
extra_environ=None, # type: Optional[Mapping[str, Any]]

0 commit comments

Comments
 (0)