Skip to content

Commit 7f9b938

Browse files
committed
Bump Ruff's target-version to Python 3.9
1 parent 3a8d079 commit 7f9b938

File tree

193 files changed

+1102
-1158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+1102
-1158
lines changed

docs/html/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pathlib
66
import re
77
import sys
8-
from typing import List, Tuple
98

109
# Add the docs/ directory to sys.path, because pip_sphinxext.py is there.
1110
docs_dir = os.path.dirname(os.path.dirname(__file__))
@@ -101,7 +100,7 @@
101100

102101

103102
# List of manual pages generated
104-
def determine_man_pages() -> List[Tuple[str, str, str, str, int]]:
103+
def determine_man_pages() -> list[tuple[str, str, str, str, int]]:
105104
"""Determine which man pages need to be generated."""
106105

107106
def to_document_name(path: str, base_dir: str) -> str:

docs/pip_sphinxext.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import pathlib
55
import re
66
import sys
7+
from collections.abc import Iterable, Iterator
78
from textwrap import dedent
8-
from typing import Dict, Iterable, Iterator, List, Optional, Union
9+
from typing import Optional, Union
910

1011
from docutils import nodes, statemachine
1112
from docutils.parsers import rst
@@ -24,7 +25,7 @@ def convert_cli_option_to_envvar(opt_name: str) -> str:
2425
return f"PIP_{normalized_opt_name}"
2526

2627

27-
def convert_cli_opt_names_to_envvars(original_cli_opt_names: List[str]) -> List[str]:
28+
def convert_cli_opt_names_to_envvars(original_cli_opt_names: list[str]) -> list[str]:
2829
return [
2930
convert_cli_option_to_envvar(opt_name) for opt_name in original_cli_opt_names
3031
]
@@ -69,7 +70,7 @@ def _iter_lines_with_refs(self, lines: Iterable[str]) -> Iterator[str]:
6970
if prev is not None:
7071
yield prev
7172

72-
def run(self) -> List[nodes.Node]:
73+
def run(self) -> list[nodes.Node]:
7374
source = self.state_machine.input_lines.source(
7475
self.lineno - self.state_machine.input_offset - 1,
7576
)
@@ -90,7 +91,7 @@ class PipCommandUsage(rst.Directive):
9091
required_arguments = 1
9192
optional_arguments = 3
9293

93-
def run(self) -> List[nodes.Node]:
94+
def run(self) -> list[nodes.Node]:
9495
cmd = create_command(self.arguments[0])
9596
cmd_prefix = "python -m pip"
9697
if len(self.arguments) > 1:
@@ -105,7 +106,7 @@ def run(self) -> List[nodes.Node]:
105106
class PipCommandDescription(rst.Directive):
106107
required_arguments = 1
107108

108-
def run(self) -> List[nodes.Node]:
109+
def run(self) -> list[nodes.Node]:
109110
node = nodes.paragraph()
110111
node.document = self.state.document
111112
desc = ViewList()
@@ -121,7 +122,7 @@ def run(self) -> List[nodes.Node]:
121122
class PipOptions(rst.Directive):
122123
def _format_option(
123124
self, option: optparse.Option, cmd_name: Optional[str] = None
124-
) -> List[str]:
125+
) -> list[str]:
125126
bookmark_line = (
126127
f".. _`{cmd_name}_{option._long_opts[0]}`:"
127128
if cmd_name
@@ -165,7 +166,7 @@ def _format_options(
165166
for line in self._format_option(option, cmd_name):
166167
self.view_list.append(line, "")
167168

168-
def run(self) -> List[nodes.Node]:
169+
def run(self) -> list[nodes.Node]:
169170
node = nodes.paragraph()
170171
node.document = self.state.document
171172
self.view_list = ViewList()
@@ -242,7 +243,7 @@ class PipCLIDirective(rst.Directive):
242243
has_content = True
243244
optional_arguments = 1
244245

245-
def run(self) -> List[nodes.Node]:
246+
def run(self) -> list[nodes.Node]:
246247
node = nodes.paragraph()
247248
node.document = self.state.document
248249

@@ -310,7 +311,7 @@ def run(self) -> List[nodes.Node]:
310311
return [node]
311312

312313

313-
def setup(app: Sphinx) -> Dict[str, Union[bool, str]]:
314+
def setup(app: Sphinx) -> dict[str, Union[bool, str]]:
314315
app.add_directive("pip-command-usage", PipCommandUsage)
315316
app.add_directive("pip-command-description", PipCommandDescription)
316317
app.add_directive("pip-command-options", PipCommandOptions)

noxfile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import os
66
import shutil
77
import sys
8+
from collections.abc import Iterator
89
from pathlib import Path
9-
from typing import Iterator, List, Tuple
1010

1111
import nox
1212

@@ -136,7 +136,7 @@ def test(session: nox.Session) -> None:
136136
def docs(session: nox.Session) -> None:
137137
session.install("-r", REQUIREMENTS["docs"])
138138

139-
def get_sphinx_build_command(kind: str) -> List[str]:
139+
def get_sphinx_build_command(kind: str) -> list[str]:
140140
# Having the conf.py in the docs/html is weird but needed because we
141141
# can not use a different configuration directory vs source directory
142142
# on RTD currently. So, we'll pass "-c docs/html" here.
@@ -214,7 +214,7 @@ def vendoring(session: nox.Session) -> None:
214214
session.run("vendoring", "sync", "-v")
215215
return
216216

217-
def pinned_requirements(path: Path) -> Iterator[Tuple[str, str]]:
217+
def pinned_requirements(path: Path) -> Iterator[tuple[str, str]]:
218218
for line in path.read_text().splitlines(keepends=False):
219219
one, sep, two = line.partition("==")
220220
if not sep:
@@ -357,7 +357,7 @@ def build_release(session: nox.Session) -> None:
357357
shutil.copy(dist, final)
358358

359359

360-
def build_dists(session: nox.Session) -> List[str]:
360+
def build_dists(session: nox.Session) -> list[str]:
361361
"""Return dists with valid metadata."""
362362
session.log(
363363
"# Check if there's any Git-untracked files before building the wheel",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ distlib = "https://bitbucket.org/pypa/distlib/raw/master/LICENSE.txt"
154154

155155
[tool.ruff]
156156
# Pinned to delay pyupgrade changes (https://github.com/pypa/pip/issues/13236)
157-
target-version = "py38" # Pin Ruff to Python 3.8
157+
target-version = "py39" # Pin Ruff to Python 3.9
158158
src = ["src"]
159159
line-length = 88
160160
extend-exclude = [

src/pip/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__version__ = "25.2.dev0"
44

55

6-
def main(args: Optional[List[str]] = None) -> int:
6+
def main(args: Optional[list[str]] = None) -> int:
77
"""This is an internal API only meant for use by pip's own console scripts.
88
99
For additional details, see https://github.com/pypa/pip/issues/7498.

src/pip/_internal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
_log.init_logging()
88

99

10-
def main(args: Optional[List[str]] = None) -> int:
10+
def main(args: Optional[list[str]] = None) -> int:
1111
"""This is preserved for old console scripts that may still be referencing
1212
it.
1313

src/pip/_internal/build_env.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import sys
88
import textwrap
99
from collections import OrderedDict
10+
from collections.abc import Iterable
1011
from types import TracebackType
11-
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type, Union
12+
from typing import TYPE_CHECKING, Optional, Union
1213

1314
from pip._vendor.packaging.version import Version
1415

@@ -27,7 +28,7 @@
2728
logger = logging.getLogger(__name__)
2829

2930

30-
def _dedup(a: str, b: str) -> Union[Tuple[str], Tuple[str, str]]:
31+
def _dedup(a: str, b: str) -> Union[tuple[str], tuple[str, str]]:
3132
return (a, b) if a != b else (a,)
3233

3334

@@ -56,7 +57,7 @@ def get_runnable_pip() -> str:
5657
return os.fsdecode(source / "__pip-runner__.py")
5758

5859

59-
def _get_system_sitepackages() -> Set[str]:
60+
def _get_system_sitepackages() -> set[str]:
6061
"""Get system site packages
6162
6263
Usually from site.getsitepackages,
@@ -87,8 +88,8 @@ def __init__(self) -> None:
8788
for name in ("normal", "overlay")
8889
)
8990

90-
self._bin_dirs: List[str] = []
91-
self._lib_dirs: List[str] = []
91+
self._bin_dirs: list[str] = []
92+
self._lib_dirs: list[str] = []
9293
for prefix in reversed(list(self._prefixes.values())):
9394
self._bin_dirs.append(prefix.bin_dir)
9495
self._lib_dirs.extend(prefix.lib_dirs)
@@ -156,7 +157,7 @@ def __enter__(self) -> None:
156157

157158
def __exit__(
158159
self,
159-
exc_type: Optional[Type[BaseException]],
160+
exc_type: Optional[type[BaseException]],
160161
exc_val: Optional[BaseException],
161162
exc_tb: Optional[TracebackType],
162163
) -> None:
@@ -168,7 +169,7 @@ def __exit__(
168169

169170
def check_requirements(
170171
self, reqs: Iterable[str]
171-
) -> Tuple[Set[Tuple[str, str]], Set[str]]:
172+
) -> tuple[set[tuple[str, str]], set[str]]:
172173
"""Return 2 sets:
173174
- conflicting requirements: set of (installed, wanted) reqs tuples
174175
- missing requirements: set of reqs
@@ -230,7 +231,7 @@ def _install_requirements(
230231
*,
231232
kind: str,
232233
) -> None:
233-
args: List[str] = [
234+
args: list[str] = [
234235
sys.executable,
235236
pip_runnable,
236237
"install",
@@ -305,7 +306,7 @@ def __enter__(self) -> None:
305306

306307
def __exit__(
307308
self,
308-
exc_type: Optional[Type[BaseException]],
309+
exc_type: Optional[type[BaseException]],
309310
exc_val: Optional[BaseException],
310311
exc_tb: Optional[TracebackType],
311312
) -> None:

src/pip/_internal/cache.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import os
77
from pathlib import Path
8-
from typing import Any, Dict, List, Optional
8+
from typing import Any, Optional
99

1010
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
1111
from pip._vendor.packaging.utils import canonicalize_name
@@ -22,7 +22,7 @@
2222
ORIGIN_JSON_NAME = "origin.json"
2323

2424

25-
def _hash_dict(d: Dict[str, str]) -> str:
25+
def _hash_dict(d: dict[str, str]) -> str:
2626
"""Return a stable sha224 of a dictionary."""
2727
s = json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
2828
return hashlib.sha224(s.encode("ascii")).hexdigest()
@@ -39,7 +39,7 @@ def __init__(self, cache_dir: str) -> None:
3939
assert not cache_dir or os.path.isabs(cache_dir)
4040
self.cache_dir = cache_dir or None
4141

42-
def _get_cache_path_parts(self, link: Link) -> List[str]:
42+
def _get_cache_path_parts(self, link: Link) -> list[str]:
4343
"""Get parts of part that must be os.path.joined with cache_dir"""
4444

4545
# We want to generate an url to use as our cache key, we don't want to
@@ -72,7 +72,7 @@ def _get_cache_path_parts(self, link: Link) -> List[str]:
7272

7373
return parts
7474

75-
def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
75+
def _get_candidates(self, link: Link, canonical_package_name: str) -> list[Any]:
7676
can_not_cache = not self.cache_dir or not canonical_package_name or not link
7777
if can_not_cache:
7878
return []
@@ -90,7 +90,7 @@ def get(
9090
self,
9191
link: Link,
9292
package_name: Optional[str],
93-
supported_tags: List[Tag],
93+
supported_tags: list[Tag],
9494
) -> Link:
9595
"""Returns a link to a cached item if it exists, otherwise returns the
9696
passed link.
@@ -128,7 +128,7 @@ def get(
128128
self,
129129
link: Link,
130130
package_name: Optional[str],
131-
supported_tags: List[Tag],
131+
supported_tags: list[Tag],
132132
) -> Link:
133133
candidates = []
134134

@@ -226,7 +226,7 @@ def get(
226226
self,
227227
link: Link,
228228
package_name: Optional[str],
229-
supported_tags: List[Tag],
229+
supported_tags: list[Tag],
230230
) -> Link:
231231
cache_entry = self.get_cache_entry(link, package_name, supported_tags)
232232
if cache_entry is None:
@@ -237,7 +237,7 @@ def get_cache_entry(
237237
self,
238238
link: Link,
239239
package_name: Optional[str],
240-
supported_tags: List[Tag],
240+
supported_tags: list[Tag],
241241
) -> Optional[CacheEntry]:
242242
"""Returns a CacheEntry with a link to a cached item if it exists or
243243
None. The cache entry indicates if the item was found in the persistent

src/pip/_internal/cli/autocompletion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import optparse
44
import os
55
import sys
6+
from collections.abc import Iterable
67
from itertools import chain
7-
from typing import Any, Iterable, List, Optional
8+
from typing import Any, Optional
89

910
from pip._internal.cli.main_parser import create_main_parser
1011
from pip._internal.commands import commands_dict, create_command
@@ -121,7 +122,7 @@ def autocomplete() -> None:
121122

122123

123124
def get_path_completion_type(
124-
cwords: List[str], cword: int, opts: Iterable[Any]
125+
cwords: list[str], cword: int, opts: Iterable[Any]
125126
) -> Optional[str]:
126127
"""Get the type of path completion (``file``, ``dir``, ``path`` or None)
127128

src/pip/_internal/cli/base_command.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
import traceback
99
from optparse import Values
10-
from typing import List, Optional, Tuple
10+
from typing import Optional
1111

1212
from pip._vendor.rich import reconfigure
1313
from pip._vendor.rich import traceback as rich_traceback
@@ -87,10 +87,10 @@ def handle_pip_version_check(self, options: Values) -> None:
8787
# are present.
8888
assert not hasattr(options, "no_index")
8989

90-
def run(self, options: Values, args: List[str]) -> int:
90+
def run(self, options: Values, args: list[str]) -> int:
9191
raise NotImplementedError
9292

93-
def _run_wrapper(self, level_number: int, options: Values, args: List[str]) -> int:
93+
def _run_wrapper(self, level_number: int, options: Values, args: list[str]) -> int:
9494
def _inner_run() -> int:
9595
try:
9696
return self.run(options, args)
@@ -147,18 +147,18 @@ def _inner_run() -> int:
147147

148148
return UNKNOWN_ERROR
149149

150-
def parse_args(self, args: List[str]) -> Tuple[Values, List[str]]:
150+
def parse_args(self, args: list[str]) -> tuple[Values, list[str]]:
151151
# factored out for testability
152152
return self.parser.parse_args(args)
153153

154-
def main(self, args: List[str]) -> int:
154+
def main(self, args: list[str]) -> int:
155155
try:
156156
with self.main_context():
157157
return self._main(args)
158158
finally:
159159
logging.shutdown()
160160

161-
def _main(self, args: List[str]) -> int:
161+
def _main(self, args: list[str]) -> int:
162162
# We must initialize this before the tempdir manager, otherwise the
163163
# configuration would not be accessible by the time we clean up the
164164
# tempdir manager.

0 commit comments

Comments
 (0)