diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index f64c0b18fe..be39007579 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1094,7 +1094,15 @@ def _added_new(self, dist): for callback in self.callbacks: callback(dist) - def __getstate__(self): + def __getstate__( + self, + ) -> tuple[ + list[str], + dict[str | None, list[str]], + dict[str, Distribution], + dict[str, str], + list[Callable[[Distribution], object]], + ]: return ( self.entries[:], self.entry_keys.copy(), @@ -1103,7 +1111,7 @@ def __getstate__(self): self.callbacks[:], ) - def __setstate__(self, e_k_b_n_c): + def __setstate__(self, e_k_b_n_c) -> None: entries, keys, by_key, normalized_to_canonical_keys, callbacks = e_k_b_n_c self.entries = entries[:] self.entry_keys = keys.copy() @@ -3171,7 +3179,7 @@ def __str__(self) -> str: version = version or "[unknown version]" return "%s %s" % (self.project_name, version) - def __getattr__(self, attr): + def __getattr__(self, attr: str): """Delegate all unrecognized public attributes to .metadata provider""" if attr.startswith('_'): raise AttributeError(attr) diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index e6d9656f10..584d2c15ac 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -81,7 +81,7 @@ def run(self): # output files are. self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=False)) - def __getattr__(self, attr): + def __getattr__(self, attr: str): "lazily compute data files" if attr == 'data_files': self.data_files = self._get_data_files() diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py index 1938434b3a..4ecbd5a1e8 100644 --- a/setuptools/command/develop.py +++ b/setuptools/command/develop.py @@ -188,7 +188,7 @@ class VersionlessRequirement: def __init__(self, dist): self.__dist = dist - def __getattr__(self, name): + def __getattr__(self, name: str): return getattr(self.__dist, name) def as_requirement(self): diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 38e1164c27..341b11a20e 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,8 +1,11 @@ +from __future__ import annotations + from setuptools import Command from setuptools.warnings import SetuptoolsDeprecationWarning -def __getattr__(name): +# Would restrict to Literal["test"], but mypy doesn't support it: https://github.com/python/mypy/issues/8203 +def __getattr__(name: str) -> type[_test]: if name == 'test': SetuptoolsDeprecationWarning.emit( "The test command is disabled and references to it are deprecated.", diff --git a/setuptools/config/expand.py b/setuptools/config/expand.py index dfee1c5d37..d12cc1d8b0 100644 --- a/setuptools/config/expand.py +++ b/setuptools/config/expand.py @@ -61,7 +61,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): + def __getattr__(self, attr: str): """Attempt to load an attribute "statically", via :func:`ast.literal_eval`.""" try: return next( diff --git a/setuptools/config/setupcfg.py b/setuptools/config/setupcfg.py index 072b787062..54469f74a3 100644 --- a/setuptools/config/setupcfg.py +++ b/setuptools/config/setupcfg.py @@ -280,7 +280,7 @@ def parsers(self): '%s must provide .parsers property' % self.__class__.__name__ ) - def __setitem__(self, option_name, value): + def __setitem__(self, option_name, value) -> None: target_obj = self.target_obj # Translate alias into real name. diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index c34f711662..cfd4cd453a 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -8,6 +8,7 @@ import tarfile from concurrent import futures from pathlib import Path +from typing import Any, Callable from zipfile import ZipFile import pytest @@ -44,7 +45,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pool = futures.ProcessPoolExecutor(max_workers=1) - def __getattr__(self, name): + def __getattr__(self, name: str) -> Callable[..., Any]: """Handles arbitrary function invocations on the build backend.""" def method(*args, **kw):