diff --git a/distutils/archive_util.py b/distutils/archive_util.py index d860f552..08ff960a 100644 --- a/distutils/archive_util.py +++ b/distutils/archive_util.py @@ -6,6 +6,7 @@ from __future__ import annotations import os +from collections.abc import Callable from typing import Literal, overload try: @@ -116,7 +117,10 @@ def _set_uid_gid(tarinfo): return tarinfo if not dry_run: - tar = tarfile.open(archive_name, f'w|{tar_compression[compress]}') + tar = tarfile.open( + archive_name, + f'w|{tar_compression[compress]}', # type: ignore[call-overload] # Typeshed doesn't allow non-literal string here + ) try: tar.add(base_dir, filter=_set_uid_gid) finally: @@ -191,7 +195,9 @@ def make_zipfile( # noqa: C901 return zip_filename -ARCHIVE_FORMATS = { +ARCHIVE_FORMATS: dict[ + str, tuple[Callable[..., str], list[tuple[str, str | None]], str] +] = { 'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"), 'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"), 'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"), diff --git a/distutils/dist.py b/distutils/dist.py index b9552a8b..6b6c011c 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -865,9 +865,7 @@ def get_command_obj( self, command: str, create: Literal[True] = True ) -> Command: ... @overload - def get_command_obj( - self, command: str, create: Literal[False] - ) -> Command | None: ... + def get_command_obj(self, command: str, create: bool) -> Command | None: ... def get_command_obj(self, command: str, create: bool = True) -> Command | None: """Return the command object for 'command'. Normally this object is cached on a previous call to 'get_command_obj()'; if no command diff --git a/distutils/filelist.py b/distutils/filelist.py index 70dc0fde..8c76a5c6 100644 --- a/distutils/filelist.py +++ b/distutils/filelist.py @@ -200,7 +200,7 @@ def process_template_line(self, line: str) -> None: # noqa: C901 @overload def include_pattern( self, - pattern: str, + pattern: str | None, anchor: bool = True, prefix: str | None = None, is_regex: Literal[False] = False, @@ -224,7 +224,7 @@ def include_pattern( ) -> bool: ... def include_pattern( self, - pattern: str | re.Pattern, + pattern: str | re.Pattern | None, anchor: bool = True, prefix: str | None = None, is_regex: bool = False, @@ -272,7 +272,7 @@ def include_pattern( @overload def exclude_pattern( self, - pattern: str, + pattern: str | None, anchor: bool = True, prefix: str | None = None, is_regex: Literal[False] = False, @@ -296,7 +296,7 @@ def exclude_pattern( ) -> bool: ... def exclude_pattern( self, - pattern: str | re.Pattern, + pattern: str | re.Pattern | None, anchor: bool = True, prefix: str | None = None, is_regex: bool = False, diff --git a/mypy.ini b/mypy.ini index 146222a5..ed31d0cf 100644 --- a/mypy.ini +++ b/mypy.ini @@ -16,20 +16,21 @@ disable_error_code = # local + # 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 + return-value, + type-var, # TODO: Resolve and re-enable these gradually operator, - attr-defined, arg-type, assignment, - call-overload, - return-value, index, - type-var, func-returns-value, union-attr, str-bytes-safe, misc, - has-type, # stdlib's test module is not typed on typeshed [mypy-test.*]