diff --git a/distutils/archive_util.py b/distutils/archive_util.py index 4a7fb9c9..c3b09097 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 cbba7746..270fcc41 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 + 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, diff --git a/distutils/dist.py b/distutils/dist.py index 02a490db..3d45e5b0 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 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 bbd6b1ea..bbbe0fb7 100644 --- a/mypy.ini +++ b/mypy.ini @@ -26,7 +26,6 @@ disable_error_code = operator, arg-type, assignment, - call-overload, union-attr, misc,