Skip to content

Commit acc62db

Browse files
authored
[3.12] gh-109413: libregrtest: Backport .py-file changes from #112558 (#112605)
1 parent 36dbebe commit acc62db

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

Lib/test/libregrtest/cmdline.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shlex
44
import sys
55
from test.support import os_helper
6-
from .utils import ALL_RESOURCES, RESOURCE_NAMES
6+
from .utils import ALL_RESOURCES, RESOURCE_NAMES, TestFilter
77

88

99
USAGE = """\
@@ -161,7 +161,7 @@ def __init__(self, **kwargs) -> None:
161161
self.forever = False
162162
self.header = False
163163
self.failfast = False
164-
self.match_tests = []
164+
self.match_tests: TestFilter = []
165165
self.pgo = False
166166
self.pgo_extended = False
167167
self.worker_json = None

Lib/test/libregrtest/refleak.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def runtest_refleak(test_name, test_func,
5252
except ImportError:
5353
zdc = None # Run unmodified on platforms without zipimport support
5454
else:
55-
zdc = zipimport._zip_directory_cache.copy()
55+
# private attribute that mypy doesn't know about:
56+
zdc = zipimport._zip_directory_cache.copy() # type: ignore[attr-defined]
5657
abcs = {}
5758
for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
5859
if not isabstract(abc):

Lib/test/libregrtest/results.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self):
3333
self.test_times: list[tuple[float, TestName]] = []
3434
self.stats = TestStats()
3535
# used by --junit-xml
36-
self.testsuite_xml: list[str] = []
36+
self.testsuite_xml: list = []
3737

3838
def is_all_good(self):
3939
return (not self.bad

Lib/test/libregrtest/run_workers.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import threading
1111
import time
1212
import traceback
13-
from typing import Literal, TextIO
13+
from typing import Any, Literal, TextIO
1414

1515
from test import support
1616
from test.support import os_helper, MS_WINDOWS
@@ -243,7 +243,9 @@ def create_json_file(self, stack: contextlib.ExitStack) -> tuple[JsonFile, TextI
243243

244244
json_fd = json_tmpfile.fileno()
245245
if MS_WINDOWS:
246-
json_handle = msvcrt.get_osfhandle(json_fd)
246+
# The msvcrt module is only available on Windows;
247+
# we run mypy with `--platform=linux` in CI
248+
json_handle: int = msvcrt.get_osfhandle(json_fd) # type: ignore[attr-defined]
247249
json_file = JsonFile(json_handle,
248250
JsonFileType.WINDOWS_HANDLE)
249251
else:
@@ -257,7 +259,7 @@ def create_worker_runtests(self, test_name: TestName, json_file: JsonFile) -> Wo
257259
else:
258260
match_tests = None
259261

260-
kwargs = {}
262+
kwargs: dict[str, Any] = {}
261263
if match_tests:
262264
kwargs['match_tests'] = [(test, True) for test in match_tests]
263265
if self.runtests.output_on_failure:
@@ -343,6 +345,7 @@ def _runtest(self, test_name: TestName) -> MultiprocessResult:
343345
json_file, json_tmpfile = self.create_json_file(stack)
344346
worker_runtests = self.create_worker_runtests(test_name, json_file)
345347

348+
retcode: str | int | None
346349
retcode, tmp_files = self.run_tmp_files(worker_runtests,
347350
stdout_file.fileno())
348351

Lib/test/libregrtest/runtests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def configure_subprocess(self, popen_kwargs: dict) -> None:
3333
popen_kwargs['pass_fds'] = [self.file]
3434
case JsonFileType.WINDOWS_HANDLE:
3535
# Windows handle
36-
startupinfo = subprocess.STARTUPINFO()
36+
# We run mypy with `--platform=linux` so it complains about this:
37+
startupinfo = subprocess.STARTUPINFO() # type: ignore[attr-defined]
3738
startupinfo.lpAttributeList = {"handle_list": [self.file]}
3839
popen_kwargs['startupinfo'] = startupinfo
3940

Lib/test/libregrtest/setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def setup_tests(runtests: RunTests):
124124
support.LONG_TIMEOUT = min(support.LONG_TIMEOUT, timeout)
125125

126126
if runtests.hunt_refleak:
127-
unittest.BaseTestSuite._cleanup = False
127+
# private attribute that mypy doesn't know about:
128+
unittest.BaseTestSuite._cleanup = False # type: ignore[attr-defined]
128129

129130
if runtests.gc_threshold is not None:
130131
gc.set_threshold(runtests.gc_threshold)

Lib/test/libregrtest/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sysconfig
1313
import tempfile
1414
import textwrap
15-
from collections.abc import Callable
15+
from collections.abc import Callable, Iterable
1616

1717
from test import support
1818
from test.support import os_helper
@@ -556,7 +556,7 @@ def is_cross_compiled():
556556
return ('_PYTHON_HOST_PLATFORM' in os.environ)
557557

558558

559-
def format_resources(use_resources: tuple[str, ...]):
559+
def format_resources(use_resources: Iterable[str]):
560560
use_resources = set(use_resources)
561561
all_resources = set(ALL_RESOURCES)
562562

@@ -596,7 +596,7 @@ def display_header(use_resources: tuple[str, ...],
596596
print("== Python build:", ' '.join(get_build_info()))
597597
print("== cwd:", os.getcwd())
598598

599-
cpu_count = os.cpu_count()
599+
cpu_count: object = os.cpu_count()
600600
if cpu_count:
601601
affinity = process_cpu_count()
602602
if affinity and affinity != cpu_count:

0 commit comments

Comments
 (0)