Skip to content

Commit b54ae61

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

File tree

9 files changed

+29
-19
lines changed

9 files changed

+29
-19
lines changed

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: 1 addition & 1 deletion
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(

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

setuptools/tests/test_build_meta.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
class BuildBackendBase:
38-
def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta'):
38+
def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta') -> None:
3939
self.cwd = cwd
4040
self.env = env or {}
4141
self.backend_name = backend_name
@@ -44,7 +44,7 @@ def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta'):
4444
class BuildBackend(BuildBackendBase):
4545
"""PEP 517 Build Backend"""
4646

47-
def __init__(self, *args, **kwargs):
47+
def __init__(self, *args, **kwargs) -> None:
4848
super().__init__(*args, **kwargs)
4949
self.pool = futures.ProcessPoolExecutor(max_workers=1)
5050

@@ -77,12 +77,12 @@ def _kill(self, pid):
7777

7878

7979
class BuildBackendCaller(BuildBackendBase):
80-
def __init__(self, *args, **kwargs):
80+
def __init__(self, *args, **kwargs) -> None:
8181
super().__init__(*args, **kwargs)
8282

8383
(self.backend_name, _, self.backend_obj) = self.backend_name.partition(':')
8484

85-
def __call__(self, name, *args, **kw):
85+
def __call__(self, name, *args, **kw) -> Any:
8686
"""Handles arbitrary function invocations on the build backend."""
8787
os.chdir(self.cwd)
8888
os.environ.update(self.env)

setuptools/tests/test_wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _check_wheel_install(
168168

169169

170170
class Record:
171-
def __init__(self, id, **kwargs):
171+
def __init__(self, id, **kwargs) -> None:
172172
self._id = id
173173
self._fields = kwargs
174174

0 commit comments

Comments
 (0)