mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-29 11:16:44 +08:00
Remove more Python 3.8 cruft (#13787)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import re
|
||||
import urllib.parse
|
||||
from collections.abc import Mapping
|
||||
@@ -19,7 +20,6 @@ from packaging.requirements import Requirement
|
||||
from packaging.specifiers import Specifier
|
||||
|
||||
from .paths import PYPROJECT_PATH, STUBS_PATH, distribution_path
|
||||
from .utils import cache
|
||||
|
||||
__all__ = [
|
||||
"NoSuchStubError",
|
||||
@@ -42,7 +42,7 @@ def _is_list_of_strings(obj: object) -> TypeGuard[list[str]]:
|
||||
return isinstance(obj, list) and all(isinstance(item, str) for item in obj)
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def _get_oldest_supported_python() -> str:
|
||||
with PYPROJECT_PATH.open("rb") as config:
|
||||
val = tomli.load(config)["tool"]["typeshed"]["oldest_supported_python"]
|
||||
@@ -79,7 +79,7 @@ class StubtestSettings:
|
||||
return ret
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def read_stubtest_settings(distribution: str) -> StubtestSettings:
|
||||
"""Return an object describing the stubtest settings for a single stubs distribution."""
|
||||
with metadata_path(distribution).open("rb") as f:
|
||||
@@ -187,7 +187,7 @@ class NoSuchStubError(ValueError):
|
||||
"""Raise NoSuchStubError to indicate that a stubs/{distribution} directory doesn't exist."""
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def read_metadata(distribution: str) -> StubMetadata:
|
||||
"""Return an object describing the metadata of a stub as given in the METADATA.toml file.
|
||||
|
||||
@@ -328,12 +328,12 @@ class PackageDependencies(NamedTuple):
|
||||
external_pkgs: tuple[Requirement, ...]
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def get_pypi_name_to_typeshed_name_mapping() -> Mapping[str, str]:
|
||||
return {read_metadata(stub_dir.name).stub_distribution: stub_dir.name for stub_dir in STUBS_PATH.iterdir()}
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def read_dependencies(distribution: str) -> PackageDependencies:
|
||||
"""Read the dependencies listed in a METADATA.toml file for a stubs package.
|
||||
|
||||
@@ -360,7 +360,7 @@ def read_dependencies(distribution: str) -> PackageDependencies:
|
||||
return PackageDependencies(tuple(typeshed), tuple(external))
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def get_recursive_requirements(package_name: str) -> PackageDependencies:
|
||||
"""Recursively gather dependencies for a single stubs package.
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import re
|
||||
import sys
|
||||
from collections.abc import Iterable, Mapping
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any, Final, NamedTuple
|
||||
from typing_extensions import TypeAlias
|
||||
@@ -26,11 +26,6 @@ from .paths import REQUIREMENTS_PATH, STDLIB_PATH, STUBS_PATH, TEST_CASES_DIR, a
|
||||
PYTHON_VERSION: Final = f"{sys.version_info.major}.{sys.version_info.minor}"
|
||||
|
||||
|
||||
# A backport of functools.cache for Python <3.9
|
||||
# This module is imported by mypy_test.py, which needs to run on 3.8 in CI
|
||||
cache = lru_cache(None)
|
||||
|
||||
|
||||
def strip_comments(text: str) -> str:
|
||||
return text.split("#")[0].strip()
|
||||
|
||||
@@ -81,7 +76,7 @@ def print_time(t: float) -> None:
|
||||
# ====================================================================
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def venv_python(venv_dir: Path) -> Path:
|
||||
if sys.platform == "win32":
|
||||
return venv_dir / "Scripts" / "python.exe"
|
||||
@@ -93,7 +88,7 @@ def venv_python(venv_dir: Path) -> Path:
|
||||
# ====================================================================
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def parse_requirements() -> Mapping[str, Requirement]:
|
||||
"""Return a dictionary of requirements from the requirements file."""
|
||||
with REQUIREMENTS_PATH.open(encoding="UTF-8") as requirements_file:
|
||||
@@ -206,7 +201,7 @@ def allowlists(distribution_name: str) -> list[str]:
|
||||
# ====================================================================
|
||||
|
||||
|
||||
@cache
|
||||
@functools.cache
|
||||
def get_gitignore_spec() -> pathspec.PathSpec:
|
||||
with open(".gitignore", encoding="UTF-8") as f:
|
||||
return pathspec.PathSpec.from_lines("gitwildmatch", f.readlines())
|
||||
|
||||
Reference in New Issue
Block a user