diff --git a/distutils/_dataclass.py b/distutils/_dataclass.py index 0ce2e3c8..41eb9b3b 100644 --- a/distutils/_dataclass.py +++ b/distutils/_dataclass.py @@ -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() @@ -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)) @@ -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 diff --git a/distutils/_modified.py b/distutils/_modified.py index 4033c079..f45ed35b 100644 --- a/distutils/_modified.py +++ b/distutils/_modified.py @@ -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( @@ -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 diff --git a/distutils/command/install_lib.py b/distutils/command/install_lib.py index a9300de7..59551a8c 100644 --- a/distutils/command/install_lib.py +++ b/distutils/command/install_lib.py @@ -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: diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index acb9d96b..96aa12d4 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -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: @@ -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' @@ -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 @@ -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 = "" expected = '"static", "shared", "dylib", "xcode_stub"' if lib_type not in eval(expected): raise ValueError(f"'lib_type' must be {expected}") @@ -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): diff --git a/mypy.ini b/mypy.ini index 48ddecfd..07f0a277 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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,