diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 68feeb0593..2bbcbffa23 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -93,7 +93,7 @@ if TYPE_CHECKING: from _typeshed import BytesPath, StrOrBytesPath, StrPath from _typeshed.importlib import LoaderProtocol - from typing_extensions import Self, TypeAlias + from typing_extensions import Never, Self, TypeAlias warnings.warn( "pkg_resources is deprecated as an API. " @@ -2365,7 +2365,7 @@ class NoDists: def __bool__(self) -> Literal[False]: return False - def __call__(self, fullpath: object): + def __call__(self, fullpath: object) -> Iterator[Never]: return iter(()) @@ -3163,13 +3163,13 @@ def __str__(self) -> str: version = version or "[unknown version]" return f"{self.project_name} {version}" - def __getattr__(self, attr: str): + def __getattr__(self, attr: str) -> Any: """Delegate all unrecognized public attributes to .metadata provider""" if attr.startswith('_'): raise AttributeError(attr) return getattr(self._provider, attr) - def __dir__(self): + def __dir__(self) -> list[str]: return list( set(super().__dir__()) | set(attr for attr in self._provider.__dir__() if not attr.startswith('_')) diff --git a/ruff.toml b/ruff.toml index b9c4a8f569..bf2d6a1159 100644 --- a/ruff.toml +++ b/ruff.toml @@ -38,7 +38,6 @@ ignore = [ "UP038", # Using `X | Y` in `isinstance` call is slower and more verbose https://github.com/astral-sh/ruff/issues/7871 # Only enforcing return type annotations for public functions "ANN202", # missing-return-type-private-function - "ANN204", # missing-return-type-special-method # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules "W191", diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 2f6fcb7cdc..4a3d0e7df8 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -9,6 +9,7 @@ from functools import partial from glob import glob from pathlib import Path +from typing import Any from more_itertools import unique_everseen @@ -81,7 +82,8 @@ def run(self) -> None: # output files are. self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=False)) - def __getattr__(self, attr: str): + # Should return "list[tuple[str, str, str, list[str]]] | Any" but can't do without typed distutils on Python 3.12+ + def __getattr__(self, attr: str) -> Any: "lazily compute data files" if attr == 'data_files': self.data_files = self._get_data_files() @@ -381,8 +383,8 @@ class _Warning(SetuptoolsDeprecationWarning): # _DUE_DATE: still not defined as this is particularly controversial. # Warning initially introduced in May 2022. See issue #3340 for discussion. - def __init__(self): - self._already_warned = set() + def __init__(self) -> None: + self._already_warned = set[str]() def is_module(self, file): return file.endswith(".py") and file[: -len(".py")].isidentifier() diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py index 7eee29d491..b61f45e3c2 100644 --- a/setuptools/command/develop.py +++ b/setuptools/command/develop.py @@ -1,5 +1,6 @@ import glob import os +from typing import Any import setuptools from setuptools import _normalization, _path, namespaces @@ -188,7 +189,7 @@ class VersionlessRequirement: def __init__(self, dist) -> None: self.__dist = dist - def __getattr__(self, name: str): + def __getattr__(self, name: str) -> Any: return getattr(self.__dist, name) def as_requirement(self): diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index b03e677757..1afd8453ff 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -397,7 +397,9 @@ def __init__(self, dist: Distribution, name: str, path_entries: list[Path]) -> N self.name = name self.path_entries = path_entries - def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]): + def __call__( + self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str] + ) -> None: entries = "\n".join(str(p.resolve()) for p in self.path_entries) contents = _encode_pth(f"{entries}\n") wheel.writestr(f"__editable__.{self.name}.pth", contents) @@ -442,7 +444,9 @@ def __init__( self._file = dist.get_command_obj("build_py").copy_file super().__init__(dist, name, [self.auxiliary_dir]) - def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]): + def __call__( + self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str] + ) -> None: self._create_links(files, mapping) super().__call__(wheel, files, mapping) @@ -536,7 +540,9 @@ def get_implementation(self) -> Iterator[tuple[str, bytes]]: content = _encode_pth(f"import {finder}; {finder}.install()") yield (f"__editable__.{self.name}.pth", content) - def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]): + def __call__( + self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str] + ) -> None: for file, content in self.get_implementation(): wheel.writestr(file, content) diff --git a/setuptools/config/expand.py b/setuptools/config/expand.py index 531f965013..d9a2ded430 100644 --- a/setuptools/config/expand.py +++ b/setuptools/config/expand.py @@ -65,7 +65,7 @@ def _find_assignments(self) -> Iterator[tuple[ast.AST, ast.AST]]: elif isinstance(statement, ast.AnnAssign) and statement.value: yield (statement.target, statement.value) - def __getattr__(self, attr: str): + def __getattr__(self, attr: str) -> Any: """Attempt to load an attribute "statically", via :func:`ast.literal_eval`.""" try: return next( @@ -390,7 +390,7 @@ def __init__(self, distribution: Distribution) -> None: self._dist = distribution self._called = False - def __call__(self): + def __call__(self) -> None: """Trigger the automatic package discovery, if it is still necessary.""" if not self._called: self._called = True @@ -404,7 +404,7 @@ def __exit__( exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, - ): + ) -> None: if self._called: self._dist.set_defaults.analyse_name() # Now we can set a default name diff --git a/setuptools/discovery.py b/setuptools/discovery.py index c888399185..606796c388 100644 --- a/setuptools/discovery.py +++ b/setuptools/discovery.py @@ -335,7 +335,7 @@ def _package_dir(self) -> dict[str, str]: def __call__( self, force: bool = False, name: bool = True, ignore_ext_modules: bool = False - ): + ) -> None: """Automatically discover missing configuration fields and modifies the given ``distribution`` object in-place. diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 1a6abebcda..b218f7964a 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1007,7 +1007,7 @@ def __str__(self) -> str: class PyPIConfig(configparser.RawConfigParser): - def __init__(self): + def __init__(self) -> None: """ Load from ~/.pypirc """ diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 2d84242d66..f1e3e986df 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -300,7 +300,7 @@ def __exit__( exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, - ): + ) -> None: self._active = False builtins.open = _open self._copy(_os) @@ -411,7 +411,7 @@ def _remap_pair(self, operation, src, dst, *args, **kw): if TYPE_CHECKING: # This is a catch-all for all the dynamically created attributes. # This isn't public API anyway - def __getattribute__(self, name: str) -> Any: ... + def __getattr__(self, name: str) -> Any: ... if hasattr(os, 'devnull'):