Skip to content

Commit 7541b67

Browse files
committed
Ran autofixes for missing-return-type-special-method (ANN204) with ignore-fully-untyped = false
1 parent f9bf422 commit 7541b67

File tree

12 files changed

+41
-28
lines changed

12 files changed

+41
-28
lines changed

pkg_resources/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
if TYPE_CHECKING:
9494
from _typeshed import BytesPath, StrOrBytesPath, StrPath
9595
from _typeshed.importlib import LoaderProtocol
96-
from typing_extensions import Self, TypeAlias
96+
from typing_extensions import Never, Self, TypeAlias
9797

9898
warnings.warn(
9999
"pkg_resources is deprecated as an API. "
@@ -2369,7 +2369,7 @@ class NoDists:
23692369
def __bool__(self) -> Literal[False]:
23702370
return False
23712371

2372-
def __call__(self, fullpath: object):
2372+
def __call__(self, fullpath: object) -> Iterator[Never]:
23732373
return iter(())
23742374

23752375

@@ -3167,13 +3167,13 @@ def __str__(self) -> str:
31673167
version = version or "[unknown version]"
31683168
return f"{self.project_name} {version}"
31693169

3170-
def __getattr__(self, attr: str):
3170+
def __getattr__(self, attr: str) -> Any:
31713171
"""Delegate all unrecognized public attributes to .metadata provider"""
31723172
if attr.startswith('_'):
31733173
raise AttributeError(attr)
31743174
return getattr(self._provider, attr)
31753175

3176-
def __dir__(self):
3176+
def __dir__(self) -> list[str]:
31773177
return list(
31783178
set(super().__dir__())
31793179
| set(attr for attr in self._provider.__dir__() if not attr.startswith('_'))

pkg_resources/tests/test_pkg_resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class EggRemover(str):
25-
def __call__(self):
25+
def __call__(self) -> None:
2626
if self in sys.path:
2727
sys.path.remove(self)
2828
if os.path.exists(self):

pkg_resources/tests/test_working_set.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from __future__ import annotations
2+
13
import functools
24
import inspect
35
import re
46
import textwrap
7+
from collections.abc import Iterable
58

69
import pytest
710

@@ -56,10 +59,10 @@ def parse_distributions(s):
5659

5760

5861
class FakeInstaller:
59-
def __init__(self, installable_dists) -> None:
62+
def __init__(self, installable_dists: Iterable[pkg_resources.Distribution]) -> None:
6063
self._installable_dists = installable_dists
6164

62-
def __call__(self, req):
65+
def __call__(self, req) -> pkg_resources.Distribution | None:
6366
return next(
6467
iter(filter(lambda dist: dist in req, self._installable_dists)), None
6568
)

ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ ignore = [
6666
"UP038", # Using `X | Y` in `isinstance` call is slower and more verbose https://github.com/astral-sh/ruff/issues/7871
6767
# Only enforcing return type annotations for public functions
6868
"ANN202", # missing-return-type-private-function
69-
"ANN204", # missing-return-type-special-method
7069
]
7170

7271
[lint.per-file-ignores]

setuptools/command/build_py.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from functools import partial
1010
from glob import glob
1111
from pathlib import Path
12+
from typing import Any
1213

1314
from more_itertools import unique_everseen
1415

@@ -81,7 +82,8 @@ def run(self) -> None:
8182
# output files are.
8283
self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=False))
8384

84-
def __getattr__(self, attr: str):
85+
# Should return "list[tuple[str, str, str, list[str]]] | Any" but can't do without typed distutils on Python 3.12+
86+
def __getattr__(self, attr: str) -> Any:
8587
"lazily compute data files"
8688
if attr == 'data_files':
8789
self.data_files = self._get_data_files()
@@ -381,8 +383,8 @@ class _Warning(SetuptoolsDeprecationWarning):
381383
# _DUE_DATE: still not defined as this is particularly controversial.
382384
# Warning initially introduced in May 2022. See issue #3340 for discussion.
383385

384-
def __init__(self):
385-
self._already_warned = set()
386+
def __init__(self) -> None:
387+
self._already_warned = set[str]()
386388

387389
def is_module(self, file):
388390
return file.endswith(".py") and file[: -len(".py")].isidentifier()

setuptools/command/editable_wheel.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ def __init__(self, dist: Distribution, name: str, path_entries: list[Path]) -> N
406406
self.name = name
407407
self.path_entries = path_entries
408408

409-
def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]):
409+
def __call__(
410+
self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]
411+
) -> None:
410412
entries = "\n".join(str(p.resolve()) for p in self.path_entries)
411413
contents = _encode_pth(f"{entries}\n")
412414
wheel.writestr(f"__editable__.{self.name}.pth", contents)
@@ -451,7 +453,9 @@ def __init__(
451453
self._file = dist.get_command_obj("build_py").copy_file
452454
super().__init__(dist, name, [self.auxiliary_dir])
453455

454-
def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]):
456+
def __call__(
457+
self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]
458+
) -> None:
455459
self._create_links(files, mapping)
456460
super().__call__(wheel, files, mapping)
457461

@@ -545,7 +549,9 @@ def get_implementation(self) -> Iterator[tuple[str, bytes]]:
545549
content = _encode_pth(f"import {finder}; {finder}.install()")
546550
yield (f"__editable__.{self.name}.pth", content)
547551

548-
def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]):
552+
def __call__(
553+
self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]
554+
) -> None:
549555
for file, content in self.get_implementation():
550556
wheel.writestr(file, content)
551557

setuptools/config/expand.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _find_assignments(self) -> Iterator[tuple[ast.AST, ast.AST]]:
6565
elif isinstance(statement, ast.AnnAssign) and statement.value:
6666
yield (statement.target, statement.value)
6767

68-
def __getattr__(self, attr: str):
68+
def __getattr__(self, attr: str) -> Any:
6969
"""Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
7070
try:
7171
return next(
@@ -390,7 +390,7 @@ def __init__(self, distribution: Distribution) -> None:
390390
self._dist = distribution
391391
self._called = False
392392

393-
def __call__(self):
393+
def __call__(self) -> None:
394394
"""Trigger the automatic package discovery, if it is still necessary."""
395395
if not self._called:
396396
self._called = True
@@ -404,7 +404,7 @@ def __exit__(
404404
exc_type: type[BaseException] | None,
405405
exc_value: BaseException | None,
406406
traceback: TracebackType | None,
407-
):
407+
) -> None:
408408
if self._called:
409409
self._dist.set_defaults.analyse_name() # Now we can set a default name
410410

setuptools/discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def _package_dir(self) -> dict[str, str]:
335335

336336
def __call__(
337337
self, force: bool = False, name: bool = True, ignore_ext_modules: bool = False
338-
):
338+
) -> None:
339339
"""Automatically discover missing configuration fields
340340
and modifies the given ``distribution`` object in-place.
341341

setuptools/tests/integration/helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
facilitate debugging.
66
"""
77

8+
from __future__ import annotations
9+
810
import os
911
import subprocess
1012
import tarfile
13+
from collections.abc import Iterator
1114
from pathlib import Path
12-
from zipfile import ZipFile
15+
from zipfile import ZipFile, ZipInfo
1316

1417

1518
def run(cmd, env=None):
@@ -35,16 +38,16 @@ def run(cmd, env=None):
3538
class Archive:
3639
"""Compatibility layer for ZipFile/Info and TarFile/Info"""
3740

38-
def __init__(self, filename):
41+
def __init__(self, filename) -> None:
3942
self._filename = filename
4043
if filename.endswith("tar.gz"):
41-
self._obj = tarfile.open(filename, "r:gz")
44+
self._obj: tarfile.TarFile | ZipFile = tarfile.open(filename, "r:gz")
4245
elif filename.endswith("zip"):
4346
self._obj = ZipFile(filename)
4447
else:
4548
raise ValueError(f"{filename} doesn't seem to be a zip or tar.gz")
4649

47-
def __iter__(self):
50+
def __iter__(self) -> Iterator[ZipInfo] | Iterator[tarfile.TarInfo]:
4851
if hasattr(self._obj, "infolist"):
4952
return iter(self._obj.infolist())
5053
return iter(self._obj)

setuptools/tests/test_bdist_wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_preserve_unicode_metadata(monkeypatch, tmp_path):
295295
class simpler_bdist_wheel(bdist_wheel):
296296
"""Avoid messing with setuptools/distutils internals"""
297297

298-
def __init__(self):
298+
def __init__(self) -> None:
299299
pass
300300

301301
@property

0 commit comments

Comments
 (0)