From 519a68f625187378e97db67ba8043c026d3b1210 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 7 Jul 2026 17:27:25 -0400 Subject: [PATCH 1/2] mypy: fix all call-overload --- distutils/archive_util.py | 7 +++++-- distutils/compilers/C/base.py | 2 +- distutils/dist.py | 4 +--- distutils/filelist.py | 8 ++++---- mypy.ini | 1 - 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/distutils/archive_util.py b/distutils/archive_util.py index 4a7fb9c9e..c3b09097d 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: @@ -114,7 +115,7 @@ def _set_uid_gid(tarinfo): tarinfo.uname = owner return tarinfo - tar = tarfile.open(archive_name, f'w|{tar_compression[compress]}') + tar = tarfile.open(archive_name, f'w|{tar_compression[compress]}') # type: ignore[call-overload] # Dynamic mode try: tar.add(base_dir, filter=_set_uid_gid) finally: @@ -185,7 +186,9 @@ def make_zipfile( 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/compilers/C/base.py b/distutils/compilers/C/base.py index cbba77460..9114799d0 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -71,7 +71,7 @@ class Compiler: # dictionary (see below -- used by the 'new_compiler()' factory # function) -- authors of new compiler interface classes are # responsible for updating 'compiler_class'! - compiler_type: ClassVar[str] = None + compiler_type: ClassVar[str | None] = None # XXX things not handled by this compiler abstraction model: # * client can't provide additional options for a compiler, diff --git a/distutils/dist.py b/distutils/dist.py index 02a490db1..3d45e5b0f 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -893,9 +893,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 70dc0fdeb..8c76a5c69 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 e8c588f0f..a3e026703 100644 --- a/mypy.ini +++ b/mypy.ini @@ -26,7 +26,6 @@ disable_error_code = operator, arg-type, assignment, - call-overload, index, union-attr, misc, From 1d201566b84f15993289f74c6f465887b6aa0a4d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 8 Jul 2026 11:27:13 -0400 Subject: [PATCH 2/2] Declare compiler_type as annotation-only ClassVar in the base class The base Compiler is abstract and every concrete subclass supplies its own compiler_type, so the base has no meaningful value to provide. An annotation-only declaration keeps the type non-null (str) without the str/None inconsistency, and makes a subclass that forgets to set it fail loudly with AttributeError rather than silently returning None. Co-Authored-By: Claude Opus 4.8 --- distutils/compilers/C/base.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index 9114799d0..270fcc414 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -63,15 +63,14 @@ class Compiler: attributes may be varied on a per-compilation or per-link basis. """ - # 'compiler_type' is a class attribute that identifies this class. It - # keeps code that wants to know what kind of compiler it's dealing with - # from having to import all possible compiler classes just to do an - # 'isinstance'. In concrete CCompiler subclasses, 'compiler_type' - # should really, really be one of the keys of the 'compiler_class' - # dictionary (see below -- used by the 'new_compiler()' factory - # function) -- authors of new compiler interface classes are - # responsible for updating 'compiler_class'! - compiler_type: ClassVar[str | None] = None + compiler_type: ClassVar[str] + """ + Identify the kind of compiler, so callers can tell compilers apart + without importing every compiler class for an ``isinstance`` check. + Set this in each concrete subclass to one of the keys of + ``compiler_class`` (see below, used by ``new_compiler()``), and update + ``compiler_class`` to match. + """ # XXX things not handled by this compiler abstraction model: # * client can't provide additional options for a compiler,