diff --git a/distutils/cmd.py b/distutils/cmd.py index f2b5b964..22447850 100644 --- a/distutils/cmd.py +++ b/distutils/cmd.py @@ -12,7 +12,7 @@ import sys from abc import abstractmethod from collections.abc import Callable, MutableSequence -from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, overload +from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, cast, overload from . import _modified, archive_util, dir_util, file_util, util from ._log import log @@ -314,7 +314,8 @@ def get_finalized_command(self, command: str, create: bool = True) -> Command: 'command', call its 'ensure_finalized()' method, and return the finalized command object. """ - cmd_obj = self.distribution.get_command_obj(command, create) + # TODO: Raise a more descriptive error when create=False or cmd_obj is None ? + cmd_obj = cast(Command, self.distribution.get_command_obj(command, create)) cmd_obj.ensure_finalized() return cmd_obj diff --git a/distutils/command/build_py.py b/distutils/command/build_py.py index d6ec7d10..59235837 100644 --- a/distutils/command/build_py.py +++ b/distutils/command/build_py.py @@ -360,6 +360,10 @@ def build_modules(self) -> None: self.build_module(module, module_file, package) def build_packages(self) -> None: + if self.packages is None: + raise TypeError( + f"{type(self).__name__}.packages is None. Is the Distribution missing packages ?" + ) for package in self.packages: # Get list of (package, module, module_file) tuples based on # scanning the package directory. 'package' is only included diff --git a/distutils/dist.py b/distutils/dist.py index 3d45e5b0..42ee591f 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -1224,7 +1224,7 @@ def _read_list(name): self.description = _read_field('summary') if 'keywords' in msg: - self.keywords = _read_field('keywords').split(',') + self.keywords = _read_field('keywords').split(',') # type:ignore[union-attr] # Manually checked self.platforms = _read_list('platform') self.classifiers = _read_list('classifier') diff --git a/distutils/filelist.py b/distutils/filelist.py index 8c76a5c6..97360b62 100644 --- a/distutils/filelist.py +++ b/distutils/filelist.py @@ -261,6 +261,7 @@ def include_pattern( # delayed loading of allfiles list if self.allfiles is None: self.findall() + assert self.allfiles is not None for name in self.allfiles: if pattern_re.search(name): diff --git a/distutils/util.py b/distutils/util.py index 19288d48..f97b686b 100644 --- a/distutils/util.py +++ b/distutils/util.py @@ -235,14 +235,9 @@ def grok_environment_error(exc: object, prefix: str = "error: ") -> str: # Needed by 'split_quoted()' -_wordchars_re = _squote_re = _dquote_re = None - - -def _init_regex(): - global _wordchars_re, _squote_re, _dquote_re - _wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*') - _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") - _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') +_wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*') +_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") +_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') def split_quoted(s: str) -> list[str]: @@ -259,8 +254,6 @@ def split_quoted(s: str) -> list[str]: # This is a nice algorithm for splitting up a single string, since it # doesn't require character-by-character examination. It was a little # bit of a brain-bender to get it working right, though... - if _wordchars_re is None: - _init_regex() s = s.strip() words = [] @@ -268,6 +261,7 @@ def split_quoted(s: str) -> list[str]: while s: m = _wordchars_re.match(s, pos) + assert m is not None end = m.end() if end == len(s): words.append(s[:end]) @@ -308,9 +302,6 @@ def split_quoted(s: str) -> list[str]: return words -# split_quoted () - - def execute( func: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], diff --git a/mypy.ini b/mypy.ini index bbbe0fb7..80ac31ec 100644 --- a/mypy.ini +++ b/mypy.ini @@ -26,7 +26,6 @@ disable_error_code = operator, arg-type, assignment, - union-attr, misc, # stdlib's test module is not typed on typeshed