Skip to content

Commit d92a644

Browse files
authored
Remove more Python 3.8 cruft (#13787)
1 parent 1edf4e8 commit d92a644

19 files changed

+63
-124
lines changed

lib/ts_utils/metadata.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import functools
89
import re
910
import urllib.parse
1011
from collections.abc import Mapping
@@ -19,7 +20,6 @@
1920
from packaging.specifiers import Specifier
2021

2122
from .paths import PYPROJECT_PATH, STUBS_PATH, distribution_path
22-
from .utils import cache
2323

2424
__all__ = [
2525
"NoSuchStubError",
@@ -42,7 +42,7 @@ def _is_list_of_strings(obj: object) -> TypeGuard[list[str]]:
4242
return isinstance(obj, list) and all(isinstance(item, str) for item in obj)
4343

4444

45-
@cache
45+
@functools.cache
4646
def _get_oldest_supported_python() -> str:
4747
with PYPROJECT_PATH.open("rb") as config:
4848
val = tomli.load(config)["tool"]["typeshed"]["oldest_supported_python"]
@@ -79,7 +79,7 @@ def system_requirements_for_platform(self, platform: str) -> list[str]:
7979
return ret
8080

8181

82-
@cache
82+
@functools.cache
8383
def read_stubtest_settings(distribution: str) -> StubtestSettings:
8484
"""Return an object describing the stubtest settings for a single stubs distribution."""
8585
with metadata_path(distribution).open("rb") as f:
@@ -187,7 +187,7 @@ class NoSuchStubError(ValueError):
187187
"""Raise NoSuchStubError to indicate that a stubs/{distribution} directory doesn't exist."""
188188

189189

190-
@cache
190+
@functools.cache
191191
def read_metadata(distribution: str) -> StubMetadata:
192192
"""Return an object describing the metadata of a stub as given in the METADATA.toml file.
193193
@@ -328,12 +328,12 @@ class PackageDependencies(NamedTuple):
328328
external_pkgs: tuple[Requirement, ...]
329329

330330

331-
@cache
331+
@functools.cache
332332
def get_pypi_name_to_typeshed_name_mapping() -> Mapping[str, str]:
333333
return {read_metadata(stub_dir.name).stub_distribution: stub_dir.name for stub_dir in STUBS_PATH.iterdir()}
334334

335335

336-
@cache
336+
@functools.cache
337337
def read_dependencies(distribution: str) -> PackageDependencies:
338338
"""Read the dependencies listed in a METADATA.toml file for a stubs package.
339339
@@ -360,7 +360,7 @@ def read_dependencies(distribution: str) -> PackageDependencies:
360360
return PackageDependencies(tuple(typeshed), tuple(external))
361361

362362

363-
@cache
363+
@functools.cache
364364
def get_recursive_requirements(package_name: str) -> PackageDependencies:
365365
"""Recursively gather dependencies for a single stubs package.
366366

lib/ts_utils/utils.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from __future__ import annotations
44

5+
import functools
56
import re
67
import sys
78
from collections.abc import Iterable, Mapping
8-
from functools import lru_cache
99
from pathlib import Path
1010
from typing import Any, Final, NamedTuple
1111
from typing_extensions import TypeAlias
@@ -26,11 +26,6 @@ def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type:
2626
PYTHON_VERSION: Final = f"{sys.version_info.major}.{sys.version_info.minor}"
2727

2828

29-
# A backport of functools.cache for Python <3.9
30-
# This module is imported by mypy_test.py, which needs to run on 3.8 in CI
31-
cache = lru_cache(None)
32-
33-
3429
def strip_comments(text: str) -> str:
3530
return text.split("#")[0].strip()
3631

@@ -81,7 +76,7 @@ def print_time(t: float) -> None:
8176
# ====================================================================
8277

8378

84-
@cache
79+
@functools.cache
8580
def venv_python(venv_dir: Path) -> Path:
8681
if sys.platform == "win32":
8782
return venv_dir / "Scripts" / "python.exe"
@@ -93,7 +88,7 @@ def venv_python(venv_dir: Path) -> Path:
9388
# ====================================================================
9489

9590

96-
@cache
91+
@functools.cache
9792
def parse_requirements() -> Mapping[str, Requirement]:
9893
"""Return a dictionary of requirements from the requirements file."""
9994
with REQUIREMENTS_PATH.open(encoding="UTF-8") as requirements_file:
@@ -206,7 +201,7 @@ def allowlists(distribution_name: str) -> list[str]:
206201
# ====================================================================
207202

208203

209-
@cache
204+
@functools.cache
210205
def get_gitignore_spec() -> pathspec.PathSpec:
211206
with open(".gitignore", encoding="UTF-8") as f:
212207
return pathspec.PathSpec.from_lines("gitwildmatch", f.readlines())

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ force-exclude = ".*_pb2.pyi"
1818
[tool.ruff]
1919
line-length = 130
2020
# Oldest supported Python version
21-
target-version = "py38"
21+
target-version = "py39"
2222
fix = true
2323
exclude = [
2424
# virtual environment

scripts/stubsabot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,6 @@ async def suggest_typeshed_obsolete(obsolete: Obsolete, session: aiohttp.ClientS
730730

731731

732732
async def main() -> None:
733-
assert sys.version_info >= (3, 9)
734-
735733
parser = argparse.ArgumentParser()
736734
parser.add_argument(
737735
"--action-level",

stdlib/@tests/stubtest_allowlists/darwin-py39.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ email.utils.getaddresses
1010
email.utils.parseaddr
1111

1212

13-
# ======
14-
# <= 3.9
15-
# ======
13+
# ========
14+
# 3.9 only
15+
# ========
1616

1717
# Added in Python 3.9.14
1818
sys.set_int_max_str_digits

stdlib/@tests/stubtest_allowlists/linux-py39.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# ======
2-
# <= 3.9
3-
# ======
1+
# ========
2+
# 3.9 only
3+
# ========
44

55
# `eventmask` argument exists at runtime, but is not correctly recognized
66
# while being inspected by stubtest. Fixed in Python 3.10.

stdlib/@tests/stubtest_allowlists/py39.txt

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# ========================
2-
# New errors in Python 3.9
3-
# ========================
4-
5-
61
# ========
72
# 3.9 only
83
# ========
@@ -16,24 +11,7 @@ collections.MappingView.__class_getitem__
1611
hmac.HMAC.digest_cons
1712
hmac.HMAC.inner
1813
hmac.HMAC.outer
19-
20-
21-
# ===========
22-
# 3.9 to 3.10
23-
# ===========
24-
25-
builtins.float.__setformat__ # Internal method for CPython test suite
26-
typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs
27-
28-
29-
# ===================================
30-
# Pre-existing errors from Python 3.8
31-
# ===================================
32-
33-
34-
# ======
35-
# <= 3.9
36-
# ======
14+
xxsubtype # module missing from the stubs
3715

3816
builtins.input # Incorrect default value in text signature, fixed in 3.10
3917
collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491
@@ -44,13 +22,13 @@ collections.ByteString # see comments in py3_common.txt
4422
collections.Callable
4523
collections.Mapping.get # Adding None to the Union messed up mypy
4624
collections.Sequence.index # Supporting None in end is not mandatory
47-
xxsubtype # module missing from the stubs
48-
4925

50-
# =======
26+
# ===========
5127
# <= 3.10
52-
# =======
28+
# ===========
5329

30+
builtins.float.__setformat__ # Internal method for CPython test suite
31+
typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs
5432
email.contentmanager.typ
5533
gettext.install # codeset default value is ['unspecified'] so can't be specified
5634
gettext.translation # codeset default value is ['unspecified'] so can't be specified

stdlib/@tests/stubtest_allowlists/win32-py39.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ email.utils.getaddresses
1111
email.utils.parseaddr
1212

1313

14-
# ======
15-
# <= 3.9
16-
# ======
14+
# ========
15+
# 3.9 only
16+
# ========
1717

1818
# Added in Python 3.9.14
1919
sys.set_int_max_str_digits

stdlib/VERSIONS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ encodings.cp273: 3.4-
145145
encodings.cp858: 3.2-
146146
encodings.koi8_t: 3.5-
147147
encodings.kz1048: 3.5-
148-
encodings.mac_centeuro: 3.0-3.8
149148
ensurepip: 3.0-
150149
enum: 3.4-
151150
errno: 3.0-

stdlib/_collections_abc.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from abc import abstractmethod
33
from types import MappingProxyType
4-
from typing import ( # noqa: Y022,Y038
4+
from typing import ( # noqa: Y022,Y038,UP035
55
AbstractSet as Set,
66
AsyncGenerator as AsyncGenerator,
77
AsyncIterable as AsyncIterable,
@@ -61,7 +61,7 @@ __all__ = [
6161
"MutableSequence",
6262
]
6363
if sys.version_info < (3, 14):
64-
from typing import ByteString as ByteString # noqa: Y057
64+
from typing import ByteString as ByteString # noqa: Y057,UP035
6565

6666
__all__ += ["ByteString"]
6767

0 commit comments

Comments
 (0)