Skip to content

missing-return-type-special-method (ANN204) with ignore-fully-untyped = false #4802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
if TYPE_CHECKING:
from _typeshed import BytesPath, StrOrBytesPath, StrPath
from _typeshed.importlib import LoaderProtocol
from typing_extensions import Self, TypeAlias
from typing_extensions import Never, Self, TypeAlias

warnings.warn(
"pkg_resources is deprecated as an API. "
Expand Down Expand Up @@ -2370,7 +2370,7 @@ class NoDists:
def __bool__(self) -> Literal[False]:
return False

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


Expand Down Expand Up @@ -3168,13 +3168,13 @@ def __str__(self) -> str:
version = version or "[unknown version]"
return f"{self.project_name} {version}"

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

def __dir__(self):
def __dir__(self) -> list[str]:
return list(
set(super().__dir__())
| set(attr for attr in self._provider.__dir__() if not attr.startswith('_'))
Expand Down
2 changes: 1 addition & 1 deletion pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class EggRemover(str):
def __call__(self):
def __call__(self) -> None:
if self in sys.path:
sys.path.remove(self)
if os.path.exists(self):
Expand Down
7 changes: 5 additions & 2 deletions pkg_resources/tests/test_working_set.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

import functools
import inspect
import re
import textwrap
from collections.abc import Iterable

import pytest

Expand Down Expand Up @@ -56,10 +59,10 @@ def parse_distributions(s):


class FakeInstaller:
def __init__(self, installable_dists) -> None:
def __init__(self, installable_dists: Iterable[pkg_resources.Distribution]) -> None:
self._installable_dists = installable_dists

def __call__(self, req):
def __call__(self, req) -> pkg_resources.Distribution | None:
return next(
iter(filter(lambda dist: dist in req, self._installable_dists)), None
)
Expand Down
1 change: 0 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ ignore = [
"UP038", # Using `X | Y` in `isinstance` call is slower and more verbose https://github.com/astral-sh/ruff/issues/7871
# Only enforcing return type annotations for public functions
"ANN202", # missing-return-type-private-function
"ANN204", # missing-return-type-special-method
]

[lint.per-file-ignores]
Expand Down
8 changes: 5 additions & 3 deletions setuptools/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from functools import partial
from glob import glob
from pathlib import Path
from typing import Any

from more_itertools import unique_everseen

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

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

def __init__(self):
self._already_warned = set()
def __init__(self) -> None:
self._already_warned = set[str]()

def is_module(self, file):
return file.endswith(".py") and file[: -len(".py")].isidentifier()
Expand Down
12 changes: 9 additions & 3 deletions setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ def __init__(self, dist: Distribution, name: str, path_entries: list[Path]) -> N
self.name = name
self.path_entries = path_entries

def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]):
def __call__(
self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]
) -> None:
entries = "\n".join(str(p.resolve()) for p in self.path_entries)
contents = _encode_pth(f"{entries}\n")
wheel.writestr(f"__editable__.{self.name}.pth", contents)
Expand Down Expand Up @@ -447,7 +449,9 @@ def __init__(
self._file = dist.get_command_obj("build_py").copy_file
super().__init__(dist, name, [self.auxiliary_dir])

def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]):
def __call__(
self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]
) -> None:
self._create_links(files, mapping)
super().__call__(wheel, files, mapping)

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

def __call__(self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]):
def __call__(
self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str]
) -> None:
for file, content in self.get_implementation():
wheel.writestr(file, content)

Expand Down
6 changes: 3 additions & 3 deletions setuptools/config/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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: str):
def __getattr__(self, attr: str) -> Any:
"""Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
try:
return next(
Expand Down Expand Up @@ -390,7 +390,7 @@ def __init__(self, distribution: Distribution) -> None:
self._dist = distribution
self._called = False

def __call__(self):
def __call__(self) -> None:
"""Trigger the automatic package discovery, if it is still necessary."""
if not self._called:
self._called = True
Expand All @@ -404,7 +404,7 @@ def __exit__(
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
):
) -> None:
if self._called:
self._dist.set_defaults.analyse_name() # Now we can set a default name

Expand Down
2 changes: 1 addition & 1 deletion setuptools/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _package_dir(self) -> dict[str, str]:

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

Expand Down
9 changes: 6 additions & 3 deletions setuptools/tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
facilitate debugging.
"""

from __future__ import annotations

import os
import subprocess
import tarfile
from collections.abc import Iterator
from pathlib import Path
from zipfile import ZipFile
from zipfile import ZipFile, ZipInfo


def run(cmd, env=None):
Expand All @@ -35,7 +38,7 @@ def run(cmd, env=None):
class Archive:
"""Compatibility layer for ZipFile/Info and TarFile/Info"""

def __init__(self, filename):
def __init__(self, filename) -> None:
self._filename = filename
if filename.endswith("tar.gz"):
self._obj = tarfile.open(filename, "r:gz")
Expand All @@ -44,7 +47,7 @@ def __init__(self, filename):
else:
raise ValueError(f"{filename} doesn't seem to be a zip or tar.gz")

def __iter__(self):
def __iter__(self) -> Iterator[ZipInfo] | Iterator[tarfile.TarInfo]:
if hasattr(self._obj, "infolist"):
return iter(self._obj.infolist())
return iter(self._obj)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_preserve_unicode_metadata(monkeypatch, tmp_path):
class simpler_bdist_wheel(bdist_wheel):
"""Avoid messing with setuptools/distutils internals"""

def __init__(self):
def __init__(self) -> None:
pass

@property
Expand Down
8 changes: 4 additions & 4 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


class BuildBackendBase:
def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta'):
def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta') -> None:
self.cwd = cwd
self.env = env or {}
self.backend_name = backend_name
Expand All @@ -44,7 +44,7 @@ def __init__(self, cwd='.', env=None, backend_name='setuptools.build_meta'):
class BuildBackend(BuildBackendBase):
"""PEP 517 Build Backend"""

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

Expand Down Expand Up @@ -77,12 +77,12 @@ def _kill(self, pid):


class BuildBackendCaller(BuildBackendBase):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

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

def __call__(self, name, *args, **kw):
def __call__(self, name, *args, **kw) -> Any:
"""Handles arbitrary function invocations on the build backend."""
os.chdir(self.cwd)
os.environ.update(self.env)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _check_wheel_install(


class Record:
def __init__(self, id, **kwargs):
def __init__(self, id, **kwargs) -> None:
self._id = id
self._fields = kwargs

Expand Down
Loading