Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions distutils/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 4 additions & 13 deletions distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"(?:[^"\\]|\\.)*"')
Comment on lines +238 to +240

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't exactly "heavy computing" is it? Did it need to be done lazily ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Looks like premature optimization. Even the re.compile calls are probably premature. Probably could have just used simple strings and compiled on demand and relied on caching in the re module to avoid duplicate work, but this approach is clean and simple enough.



def split_quoted(s: str) -> list[str]:
Expand All @@ -259,15 +254,14 @@ 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 = []
pos = 0

while s:
m = _wordchars_re.match(s, pos)
assert m is not None
end = m.end()
if end == len(s):
words.append(s[:end])
Expand Down Expand Up @@ -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]],
Expand Down
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ disable_error_code =
operator,
arg-type,
assignment,
union-attr,
misc,

# stdlib's test module is not typed on typeshed
Expand Down
Loading