Skip to content
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

Type all get/set dunders #4584

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,15 @@ def _added_new(self, dist):
for callback in self.callbacks:
callback(dist)

def __getstate__(self):
def __getstate__(
self,
) -> tuple[
list[str],
dict[str | None, list[str]],
dict[str, Distribution],
dict[str, str],
list[Callable[[Distribution], object]],
]:
return (
self.entries[:],
self.entry_keys.copy(),
Expand All @@ -1103,7 +1111,7 @@ def __getstate__(self):
self.callbacks[:],
)

def __setstate__(self, e_k_b_n_c):
def __setstate__(self, e_k_b_n_c) -> None:
entries, keys, by_key, normalized_to_canonical_keys, callbacks = e_k_b_n_c
self.entries = entries[:]
self.entry_keys = keys.copy()
Expand Down Expand Up @@ -3171,7 +3179,7 @@ def __str__(self) -> str:
version = version or "[unknown version]"
return "%s %s" % (self.project_name, version)

def __getattr__(self, attr):
def __getattr__(self, attr: str):
"""Delegate all unrecognized public attributes to .metadata provider"""
if attr.startswith('_'):
raise AttributeError(attr)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def run(self):
# output files are.
self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=False))

def __getattr__(self, attr):
def __getattr__(self, attr: str):
"lazily compute data files"
if attr == 'data_files':
self.data_files = self._get_data_files()
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class VersionlessRequirement:
def __init__(self, dist):
self.__dist = dist

def __getattr__(self, name):
def __getattr__(self, name: str):
return getattr(self.__dist, name)

def as_requirement(self):
Expand Down
5 changes: 4 additions & 1 deletion setuptools/command/test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations

from setuptools import Command
from setuptools.warnings import SetuptoolsDeprecationWarning


def __getattr__(name):
# Would restrict to Literal["test"], but mypy doesn't support it: https://github.com/python/mypy/issues/8203
def __getattr__(name: str) -> type[_test]:
if name == 'test':
SetuptoolsDeprecationWarning.emit(
"The test command is disabled and references to it are deprecated.",
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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):
def __getattr__(self, attr: str):
"""Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
try:
return next(
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def parsers(self):
'%s must provide .parsers property' % self.__class__.__name__
)

def __setitem__(self, option_name, value):
def __setitem__(self, option_name, value) -> None:
target_obj = self.target_obj

# Translate alias into real name.
Expand Down
3 changes: 2 additions & 1 deletion setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tarfile
from concurrent import futures
from pathlib import Path
from typing import Any, Callable
from zipfile import ZipFile

import pytest
Expand Down Expand Up @@ -44,7 +45,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.pool = futures.ProcessPoolExecutor(max_workers=1)

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

def method(*args, **kw):
Expand Down
Loading