10000 mypy: Fix all union-attr by Avasam · Pull Request #366 · pypa/distutils · GitHub
[go: up one dir, main page]

Skip to content

mypy: Fix all union-attr #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def build_modules(self) -> None:
self.build_module(module, module_file, package)

def build_packages(self) -> None:
for package in self.packages:
for package in self.packages or ():
10000
Copy link
Contributor Author
@Avasam Avasam May 4, 2025

Choose a reason for hiding this comment

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

This is a change in behaviour as it would graciously do nothing instead of raising if self.packages is still None.

If it makes more sense to raise, a clearer error than TypeError: 'NoneType' object is not iterable can be raised instead.

# Get list of (package, module, module_file) tuples based on
# scanning the package directory. 'package' is only included
# in the tuple so that 'find_modules()' and
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)

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 ?



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
0