Skip to content

Commit 9876b34

Browse files
committed
mypy: Fix all union-attr
1 parent 0ef914d commit 9876b34

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

distutils/command/build_py.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ def build_modules(self) -> None:
360360
self.build_module(module, module_file, package)
361361

362362
def build_packages(self) -> None:
363+
if self.packages is None:
364+
raise TypeError(
365+
f"{type(self).__name__}.packages is None. Is the Distribution missing packages ?"
366+
)
363367
for package in self.packages:
364368
# Get list of (package, module, module_file) tuples based on
365369
# scanning the package directory. 'package' is only included

distutils/compilers/C/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Compiler:
7070
# dictionary (see below -- used by the 'new_compiler()' factory
7171
# function) -- authors of new compiler interface classes are
7272
# responsible for updating 'compiler_class'!
73-
compiler_type: ClassVar[str] = None # type: ignore[assignment]
73+
compiler_type: ClassVar[str] = None # pyright: ignore[reportAssignmentType]
7474

7575
# XXX things not handled by this compiler abstraction model:
7676
# * client can't provide additional options for a compiler,

distutils/dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ def _read_list(name):
11981198
self.description = _read_field('summary')
11991199

12001200
if 'keywords' in msg:
1201-
self.keywords = _read_field('keywords').split(',')
1201+
self.keywords = _read_field('keywords').split(',') # type:ignore[union-attr] # Manually checked
12021202

12031203
self.platforms = _read_list('platform')
12041204
self.classifiers = _read_list('classifier')

distutils/filelist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def include_pattern(
261261
# delayed loading of allfiles list
262262
if self.allfiles is None:
263263
self.findall()
264+
assert self.allfiles is not None
264265

265266
for name in self.allfiles:
266267
if pattern_re.search(name):

distutils/sysconfig.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@ def customize_compiler(compiler: CCompiler) -> None:
324324
'AR',
325325
'ARFLAGS',
326326
)
327+
assert isinstance(cc, str)
328+
assert isinstance(cxx, str)
329+
assert isinstance(cflags, str)
330+
assert isinstance(ccshared, str)
331+
assert isinstance(ldshared, str)
332+
assert isinstance(ldcxxshared, str)
333+
assert isinstance(shlib_suffix, str)
334+
assert isinstance(ar_flags, str)
335+
ar = os.environ.get('AR', ar)
336+
assert isinstance(ar, str)
327337

328338
cxxflags = cflags
329339

@@ -354,8 +364,6 @@ def customize_compiler(compiler: CCompiler) -> None:
354364
ldshared = _add_flags(ldshared, 'CPP')
355365
ldcxxshared = _add_flags(ldcxxshared, 'CPP')
356366

357-
ar = os.environ.get('AR', ar)
358-
359367
archiver = ar + ' ' + os.environ.get('ARFLAGS', ar_flags)
360368
cc_cmd = cc + ' ' + cflags
361369
cxx_cmd = cxx + ' ' + cxxflags

distutils/util.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,9 @@ def grok_environment_error(exc: object, prefix: str = "error: ") -> str:
232232

233233

234234
# Needed by 'split_quoted()'
235-
_wordchars_re = _squote_re = _dquote_re = None
236-
237-
238-
def _init_regex():
239-
global _wordchars_re, _squote_re, _dquote_re
240-
_wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*')
241-
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
242-
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
235+
_wordchars_re = re.compile(rf'[^\\\'\"{string.whitespace} ]*')
236+
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
237+
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
243238

244239

245240
def split_quoted(s: str) -> list[str]:
@@ -256,15 +251,14 @@ def split_quoted(s: str) -> list[str]:
256251
# This is a nice algorithm for splitting up a single string, since it
257252
# doesn't require character-by-character examination. It was a little
258253
# bit of a brain-bender to get it working right, though...
259-
if _wordchars_re is None:
260-
_init_regex()
261254

262255
s = s.strip()
263256
words = []
264257
pos = 0
265258

266259
while s:
267260
m = _wordchars_re.match(s, pos)
261+
assert m is not None
268262
end = m.end()
269263
if end == len(s):
270264
words.append(s[:end])
@@ -305,9 +299,6 @@ def split_quoted(s: str) -> list[str]:
305299
return words
306300

307301

308-
# split_quoted ()
309-
310-
311302
def execute(
312303
func: Callable[[Unpack[_Ts]], object],
313304
args: tuple[Unpack[_Ts]],

mypy.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ disable_error_code =
2929
call-overload,
3030
index,
3131
func-returns-value,
32-
union-attr,
3332
str-bytes-safe,
3433
misc,
3534

0 commit comments

Comments
 (0)