Skip to content
Open
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
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/compilers/C/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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 # type: ignore[assignment]
compiler_type: ClassVar[str] = None # pyright: ignore[reportAssignmentType]

# XXX things not handled by this compiler abstraction model:
# * client can't provide additional options for a compiler,
Expand Down
2 changes: 1 addition & 1 deletion distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,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
12 changes: 10 additions & 2 deletions distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ def customize_compiler(compiler: CCompiler) -> None:
'AR',
'ARFLAGS',
)
assert isinstance(cc, str)
assert isinstance(cxx, str)
assert isinstance(cflags, str)
assert isinstance(ccshared, str)
assert isinstance(ldshared, str)
assert isinstance(ldcxxshared, str)
assert isinstance(shlib_suffix, str)
assert isinstance(ar_flags, str)
ar = os.environ.get('AR', ar)
assert isinstance(ar, str)
Comment on lines +327 to +336
Copy link
Member

Choose a reason for hiding this comment

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

I mentioned in another PR - I'm not sure these changes are stable. I'm worried there are edge cases that would begin to fail with this change. Let's be confident that this change doesn't break anything (and consider using casts to retain the current behavior if appropriate).


cxxflags = cflags

Expand Down Expand Up @@ -354,8 +364,6 @@ def customize_compiler(compiler: CCompiler) -> None:
ldshared = _add_flags(ldshared, 'CPP')
ldcxxshared = _add_flags(ldcxxshared, 'CPP')

ar = os.environ.get('AR', ar)

archiver = ar + ' ' + os.environ.get('ARFLAGS', ar_flags)
cc_cmd = cc + ' ' + cflags
cxx_cmd = cxx + ' ' + cxxflags
Expand Down
17 changes: 4 additions & 13 deletions distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,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 +235 to +237
Copy link
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
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 @@ -256,15 +251,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 @@ -305,9 +299,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
11 changes: 6 additions & 5 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ 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.*]
Expand Down
Loading