Skip to content
Open
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
8 changes: 4 additions & 4 deletions distutils/_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import warnings
from dataclasses import dataclass, fields
from functools import wraps
from typing import TypeVar
from typing import Any, TypeVar, cast

from .compat.py310 import dataclass_transform

_T = TypeVar("_T", bound=type)
_T = TypeVar("_T", bound=type[Any])


@dataclass_transform()
Expand All @@ -26,7 +26,7 @@ def lenient_dataclass(**dc_kwargs):
"""

@wraps(dataclass)
def _wrap(cls: _T) -> _T: # type: ignore[var-annotated]
def _wrap(cls: _T) -> _T:
cls = dataclass(**dc_kwargs)(cls)
# Allowed field names in order
safe = tuple(f.name for f in fields(cls))
Expand All @@ -50,6 +50,6 @@ def _wrapped_init(self, *args, **kwargs):
return orig_init(self, **positional, **keywords)

cls.__init__ = _wrapped_init
return cls
return cast("_T", cls)

return _wrap
8 changes: 6 additions & 2 deletions distutils/_modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def newer_pairwise(
of 'newer()'.
"""
newer_pairs = filter(splat(newer), zip(sources, targets, strict=True))
return tuple(map(list, zip(*newer_pairs, strict=False))) or ([], [])

return (
tuple(map(list, zip(*newer_pairs, strict=False))) # type: ignore[return-value] # FIXME: pypa/distutils#411
or ([], [])
)


def newer_group(
Expand Down Expand Up @@ -91,4 +95,4 @@ def missing_as_newer(source):
)


newer_pairwise_group = functools.partial(newer_pairwise, newer=newer_group)
newer_pairwise_group = functools.partial(newer_pairwise, newer=newer_group) # type: ignore[type-var] # FIXME: pypa/distutils#411
2 changes: 1 addition & 1 deletion distutils/command/install_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def install(self) -> list[str] | Any:
self.warn(
f"'{self.build_dir}' does not exist -- no Python modules to install"
)
return
return None
return outfiles

def byte_compile(self, files) -> None:
Expand Down
24 changes: 6 additions & 18 deletions distutils/compilers/C/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
_StrPathT = TypeVar("_StrPathT", bound="str | os.PathLike[str]")
_BytesPathT = TypeVar("_BytesPathT", bound="bytes | os.PathLike[bytes]")


class Compiler:
Expand Down Expand Up @@ -431,7 +430,7 @@ def _fix_compile_args(
output_dir: str | None,
macros: list[_Macro] | None,
include_dirs: list[str] | tuple[str, ...] | None,
) -> tuple[str, list[_Macro], list[str]]:
) -> tuple[str | None, list[_Macro], list[str]]:
"""Typecheck and fix-up some of the arguments to the 'compile()'
method, and return fixed-up values. Specifically: if 'output_dir'
is None, replaces it with 'self.output_dir'; ensures that 'macros'
Expand Down Expand Up @@ -483,7 +482,7 @@ def _prep_compile(self, sources, output_dir, depends=None):

def _fix_object_args(
self, objects: list[str] | tuple[str, ...], output_dir: str | None
) -> tuple[list[str], str]:
) -> tuple[list[str], str | None]:
"""Typecheck and fix up some arguments supplied to various methods.
Specifically: ensure that 'objects' is a list; if output_dir is
None, replace with self.output_dir. Return fixed versions of
Expand Down Expand Up @@ -1123,9 +1122,10 @@ def library_filename(
libname: str,
lib_type: str = "static",
strip_dir: bool = False,
output_dir: str | os.PathLike[str] = "", # or 'shared'
output_dir: str | os.PathLike[str] | None = "", # or 'shared'
):
assert output_dir is not None
if output_dir is None:
output_dir = ""
Comment on lines +1127 to +1128

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels odd allowing this to be None for type checking purposes, only to immediatly assert it can't be None.
If assert output_dir is not None is an invariant that must be kept, then msvc.Compiler.create_static_lib should check the return of _fix_object_args before passing it to library_filename

expected = '"static", "shared", "dylib", "xcode_stub"'
if lib_type not in eval(expected):
raise ValueError(f"'lib_type' must be {expected}")
Expand Down Expand Up @@ -1195,19 +1195,7 @@ def spawn(
with _translate_errors(cmd):
self.call(cmd, env=env, **kwargs)

@overload
def move_file(
self, src: str | os.PathLike[str], dst: _StrPathT
) -> _StrPathT | str: ...
@overload
def move_file(
self, src: bytes | os.PathLike[bytes], dst: _BytesPathT
) -> _BytesPathT | bytes: ...
def move_file(
self,
src: str | os.PathLike[str] | bytes | os.PathLike[bytes],
dst: str | os.PathLike[str] | bytes | os.PathLike[bytes],
) -> str | os.PathLike[str] | bytes | os.PathLike[bytes]:
def move_file(self, src: str | os.PathLike[str], dst: _StrPathT) -> _StrPathT | str:
return shutil.move(src, dst)

def mkpath(self, name, mode=0o777):
Expand Down
4 changes: 0 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ disable_error_code =
# Code that is too dynamic using variable command names;
# and code that uses platform checks mypy doesn't understand
attr-defined,
# These reveal issues in distutils/_modified.py that should be fixed
# https://github.com/pypa/distutils/issues/411
return-value,
type-var,
# TODO: Resolve and re-enable these gradually
operator,
arg-type,
Expand Down
Loading