Skip to content

Commit 9b2d09c

Browse files
Avasamabravalheri
authored andcommitted
Type all get/set dunders
1 parent 2d63f5c commit 9b2d09c

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

pkg_resources/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,15 @@ def _added_new(self, dist):
10941094
for callback in self.callbacks:
10951095
callback(dist)
10961096

1097-
def __getstate__(self):
1097+
def __getstate__(
1098+
self,
1099+
) -> tuple[
1100+
list[str],
1101+
dict[str | None, list[str]],
1102+
dict[str, Distribution],
1103+
dict[str, str],
1104+
list[Callable[[Distribution], object]],
1105+
]:
10981106
return (
10991107
self.entries[:],
11001108
self.entry_keys.copy(),
@@ -1103,7 +1111,7 @@ def __getstate__(self):
11031111
self.callbacks[:],
11041112
)
11051113

1106-
def __setstate__(self, e_k_b_n_c):
1114+
def __setstate__(self, e_k_b_n_c) -> None:
11071115
entries, keys, by_key, normalized_to_canonical_keys, callbacks = e_k_b_n_c
11081116
self.entries = entries[:]
11091117
self.entry_keys = keys.copy()
@@ -3171,7 +3179,7 @@ def __str__(self) -> str:
31713179
version = version or "[unknown version]"
31723180
return "%s %s" % (self.project_name, version)
31733181

3174-
def __getattr__(self, attr):
3182+
def __getattr__(self, attr: str):
31753183
"""Delegate all unrecognized public attributes to .metadata provider"""
31763184
if attr.startswith('_'):
31773185
raise AttributeError(attr)

setuptools/command/build_py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def run(self):
8181
# output files are.
8282
self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=False))
8383

84-
def __getattr__(self, attr):
84+
def __getattr__(self, attr: str):
8585
"lazily compute data files"
8686
if attr == 'data_files':
8787
self.data_files = self._get_data_files()

setuptools/command/develop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class VersionlessRequirement:
188188
def __init__(self, dist):
189189
self.__dist = dist
190190

191-
def __getattr__(self, name):
191+
def __getattr__(self, name: str):
192192
return getattr(self.__dist, name)
193193

194194
def as_requirement(self):

setuptools/command/test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
pass
7+
18
from setuptools import Command
29
from setuptools.warnings import SetuptoolsDeprecationWarning
310

411

5-
def __getattr__(name):
12+
# Would restrict to Literal["test"], but mypy doesn't support it: https://github.com/python/mypy/issues/8203
13+
def __getattr__(name: str) -> type[_test]:
614
if name == 'test':
715
SetuptoolsDeprecationWarning.emit(
816
"The test command is disabled and references to it are deprecated.",

setuptools/config/expand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _find_assignments(self) -> Iterator[tuple[ast.AST, ast.AST]]:
6161
elif isinstance(statement, ast.AnnAssign) and statement.value:
6262
yield (statement.target, statement.value)
6363

64-
def __getattr__(self, attr):
64+
def __getattr__(self, attr: str):
6565
"""Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
6666
try:
6767
return next(

setuptools/config/setupcfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def parsers(self):
280280
'%s must provide .parsers property' % self.__class__.__name__
281281
)
282282

283-
def __setitem__(self, option_name, value):
283+
def __setitem__(self, option_name, value) -> None:
284284
target_obj = self.target_obj
285285

286286
# Translate alias into real name.

setuptools/tests/test_build_meta.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import tarfile
99
from concurrent import futures
1010
from pathlib import Path
11+
from typing import Any, Callable
1112
from zipfile import ZipFile
1213

1314
import pytest
@@ -44,7 +45,7 @@ def __init__(self, *args, **kwargs):
4445
super().__init__(*args, **kwargs)
4546
self.pool = futures.ProcessPoolExecutor(max_workers=1)
4647

47-
def __getattr__(self, name):
48+
def __getattr__(self, name: str) -> Callable[..., Any]:
4849
"""Handles arbitrary function invocations on the build backend."""
4950

5051
def method(*args, **kw):

0 commit comments

Comments
 (0)