Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f4df09

Browse files
committedAug 20, 2024·
Type all get/set dunders
1 parent ebddeb3 commit 6f4df09

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed
 

‎pkg_resources/__init__.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,10 @@ class WorkingSet:
628628
def __init__(self, entries: Iterable[str] | None = None):
629629
"""Create working set from list of path entries (default=sys.path)"""
630630
self.entries: list[str] = []
631-
self.entry_keys = {}
632-
self.by_key = {}
633-
self.normalized_to_canonical_keys = {}
634-
self.callbacks = []
631+
self.entry_keys: dict[str | None, list[str]] = {}
632+
self.by_key: dict[str, Distribution] = {}
633+
self.normalized_to_canonical_keys: dict[str, str] = {}
634+
self.callbacks: list[Callable[[Distribution], object]] = []
635635

636636
if entries is None:
637637
entries = sys.path
@@ -1087,7 +1087,15 @@ def _added_new(self, dist):
10871087
for callback in self.callbacks:
10881088
callback(dist)
10891089

1090-
def __getstate__(self):
1090+
def __getstate__(
1091+
self,
1092+
) -> tuple[
1093+
list[str],
1094+
dict[str | None, list[str]],
1095+
dict[str, Distribution],
1096+
dict[str, str],
1097+
list[Callable[[Distribution], object]],
1098+
]:
10911099
return (
10921100
self.entries[:],
10931101
self.entry_keys.copy(),
@@ -1096,7 +1104,7 @@ def __getstate__(self):
10961104
self.callbacks[:],
10971105
)
10981106

1099-
def __setstate__(self, e_k_b_n_c):
1107+
def __setstate__(self, e_k_b_n_c) -> None:
11001108
entries, keys, by_key, normalized_to_canonical_keys, callbacks = e_k_b_n_c
11011109
self.entries = entries[:]
11021110
self.entry_keys = keys.copy()
@@ -3163,7 +3171,7 @@ def __str__(self):
31633171
version = version or "[unknown version]"
31643172
return "%s %s" % (self.project_name, version)
31653173

3166-
def __getattr__(self, attr):
3174+
def __getattr__(self, attr: str):
31673175
"""Delegate all unrecognized public attributes to .metadata provider"""
31683176
if attr.startswith('_'):
31693177
raise AttributeError(attr)

‎setuptools/command/build_py.py

+1-1
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

+1-1
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

+9-1
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 Litera["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

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def parsers(self):
277277
'%s must provide .parsers property' % self.__class__.__name__
278278
)
279279

280-
def __setitem__(self, option_name, value):
280+
def __setitem__(self, option_name, value) -> None:
281281
target_obj = self.target_obj
282282

283283
# Translate alias into real name.

‎setuptools/tests/test_build_meta.py

+2-1
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)
Please sign in to comment.