From 248ee131d9223848853bacb4df11b1d1e1f826e9 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 May 2025 11:48:10 -0400 Subject: [PATCH 1/2] Re-organize mypy errors --- mypy.ini | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mypy.ini b/mypy.ini index 146222a5..5244a0e9 100644 --- a/mypy.ini +++ b/mypy.ini @@ -16,20 +16,22 @@ 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.*] From 565f29c6d72aa379b10ddc9dce11529ba1795dad Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 4 May 2025 12:39:30 -0400 Subject: [PATCH 2/2] mypy: fix all call-overload --- distutils/archive_util.py | 10 ++++++++-- distutils/dist.py | 4 +--- distutils/filelist.py | 8 ++++---- mypy.ini | 1 - 4 files changed, 13 insertions(+), 10 deletions(-) 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 5244a0e9..ed31d0cf 100644 --- a/mypy.ini +++ b/mypy.ini @@ -26,7 +26,6 @@ disable_error_code = operator, arg-type, assignment, - call-overload, index, func-returns-value, union-attr,