Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/ts_utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import functools
import re
import urllib.parse
from collections.abc import Mapping
Expand All @@ -19,7 +20,6 @@
from packaging.specifiers import Specifier

from .paths import PYPROJECT_PATH, STUBS_PATH, distribution_path
from .utils import cache

__all__ = [
"NoSuchStubError",
Expand All @@ -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"]
Expand Down Expand Up @@ -79,7 +79,7 @@ def system_requirements_for_platform(self, platform: str) -> list[str]:
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:
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down
13 changes: 4 additions & 9 deletions lib/ts_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,11 +26,6 @@ def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type:
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()

Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ force-exclude = ".*_pb2.pyi"
[tool.ruff]
line-length = 130
# Oldest supported Python version
target-version = "py38"
target-version = "py39"
fix = true
exclude = [
# virtual environment
Expand Down
2 changes: 0 additions & 2 deletions scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,6 @@ async def suggest_typeshed_obsolete(obsolete: Obsolete, session: aiohttp.ClientS


async def main() -> None:
assert sys.version_info >= (3, 9)

parser = argparse.ArgumentParser()
parser.add_argument(
"--action-level",
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@tests/stubtest_allowlists/darwin-py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ email.utils.getaddresses
email.utils.parseaddr


# ======
# <= 3.9
# ======
# ========
# 3.9 only
# ========

# Added in Python 3.9.14
sys.set_int_max_str_digits
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@tests/stubtest_allowlists/linux-py39.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ======
# <= 3.9
# ======
# ========
# 3.9 only
# ========

# `eventmask` argument exists at runtime, but is not correctly recognized
# while being inspected by stubtest. Fixed in Python 3.10.
Expand Down
32 changes: 5 additions & 27 deletions stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# ========================
# New errors in Python 3.9
# ========================


# ========
# 3.9 only
# ========
Expand All @@ -16,24 +11,7 @@ collections.MappingView.__class_getitem__
hmac.HMAC.digest_cons
hmac.HMAC.inner
hmac.HMAC.outer


# ===========
# 3.9 to 3.10
# ===========

builtins.float.__setformat__ # Internal method for CPython test suite
typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs


# ===================================
# Pre-existing errors from Python 3.8
# ===================================


# ======
# <= 3.9
# ======
xxsubtype # module missing from the stubs

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


# =======
# ===========
# <= 3.10
# =======
# ===========

builtins.float.__setformat__ # Internal method for CPython test suite
typing._SpecialForm.__mro_entries__ # Exists at runtime, but missing from stubs
email.contentmanager.typ
gettext.install # codeset default value is ['unspecified'] so can't be specified
gettext.translation # codeset default value is ['unspecified'] so can't be specified
Expand Down
6 changes: 3 additions & 3 deletions stdlib/@tests/stubtest_allowlists/win32-py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ email.utils.getaddresses
email.utils.parseaddr


# ======
# <= 3.9
# ======
# ========
# 3.9 only
# ========

# Added in Python 3.9.14
sys.set_int_max_str_digits
Expand Down
1 change: 0 additions & 1 deletion stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ encodings.cp273: 3.4-
encodings.cp858: 3.2-
encodings.koi8_t: 3.5-
encodings.kz1048: 3.5-
encodings.mac_centeuro: 3.0-3.8
ensurepip: 3.0-
enum: 3.4-
errno: 3.0-
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from abc import abstractmethod
from types import MappingProxyType
from typing import ( # noqa: Y022,Y038
from typing import ( # noqa: Y022,Y038,UP035
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
Expand Down Expand Up @@ -61,7 +61,7 @@ __all__ = [
"MutableSequence",
]
if sys.version_info < (3, 14):
from typing import ByteString as ByteString # noqa: Y057
from typing import ByteString as ByteString # noqa: Y057,UP035

__all__ += ["ByteString"]

Expand Down
10 changes: 3 additions & 7 deletions stdlib/array.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import sys
from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
from collections.abc import Iterable

# pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence
from typing import Any, ClassVar, Literal, MutableSequence, SupportsIndex, TypeVar, overload # noqa: Y022
from collections.abc import Iterable, MutableSequence
from types import GenericAlias
from typing import Any, ClassVar, Literal, SupportsIndex, TypeVar, overload
from typing_extensions import Self, TypeAlias

if sys.version_info >= (3, 12):
from types import GenericAlias

_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
_FloatTypeCode: TypeAlias = Literal["f", "d"]
_UnicodeTypeCode: TypeAlias = Literal["u"]
Expand Down
2 changes: 1 addition & 1 deletion stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ from types import CellType, CodeType, GenericAlias, TracebackType

# mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping}
# are imported from collections.abc in builtins.pyi
from typing import ( # noqa: Y022
from typing import ( # noqa: Y022,UP035
IO,
Any,
BinaryIO,
Expand Down
4 changes: 1 addition & 3 deletions stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ else:

from _typeshed import SupportsWrite
from collections.abc import Collection, Iterable, Mapping, Sequence
from types import GenericAlias
from typing import Any, Generic, Literal, TypeVar, overload
from typing_extensions import Self

if sys.version_info >= (3, 12):
from types import GenericAlias

__all__ = [
"QUOTE_MINIMAL",
"QUOTE_ALL",
Expand Down
21 changes: 0 additions & 21 deletions stdlib/encodings/mac_centeuro.pyi

This file was deleted.

5 changes: 1 addition & 4 deletions stdlib/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ from io import TextIOWrapper
from re import Pattern
from string import Template
from time import struct_time
from types import FrameType, TracebackType
from types import FrameType, GenericAlias, TracebackType
from typing import Any, ClassVar, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload
from typing_extensions import Self, TypeAlias, deprecated

if sys.version_info >= (3, 11):
from types import GenericAlias

__all__ = [
"BASIC_FORMAT",
"BufferingFormatter",
Expand Down
3 changes: 2 additions & 1 deletion stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ from collections.abc import (
Iterable,
Iterator,
KeysView,
Mapping, # noqa: Y022
MutableSequence,
ValuesView,
)
from importlib.machinery import ModuleSpec

# pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping
from typing import Any, ClassVar, Literal, Mapping, TypeVar, final, overload # noqa: Y022
from typing import Any, ClassVar, Literal, TypeVar, final, overload
from typing_extensions import ParamSpec, Self, TypeAliasType, TypeVarTuple, deprecated

__all__ = [
Expand Down
Loading