Skip to content

Commit 36dbebe

Browse files
[3.12] gh-109413: libregrtest: enable mypy's --strict-optional check on most files (#112586) (#112602)
gh-109413: libregrtest: enable mypy's `--strict-optional` check on most files (#112586) Co-authored-by: Victor Stinner <[email protected]>
1 parent 4fc010c commit 36dbebe

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

Lib/test/libregrtest/mypy.ini

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Config file for running mypy on libregrtest.
2+
# Run mypy by invoking `mypy --config-file Lib/test/libregrtest/mypy.ini`
3+
# on the command-line from the repo root
4+
5+
[mypy]
6+
files = Lib/test/libregrtest
7+
explicit_package_bases = True
8+
python_version = 3.12
9+
platform = linux
10+
pretty = True
11+
12+
# Enable most stricter settings
13+
enable_error_code = ignore-without-code
14+
strict = True
15+
16+
# Various stricter settings that we can't yet enable
17+
# Try to enable these in the following order:
18+
disallow_any_generics = False
19+
disallow_incomplete_defs = False
20+
disallow_untyped_calls = False
21+
disallow_untyped_defs = False
22+
check_untyped_defs = False
23+
warn_return_any = False
24+
25+
disable_error_code = return
26+
27+
# Enable --strict-optional for these ASAP:
28+
[mypy-Lib.test.libregrtest.main.*,Lib.test.libregrtest.run_workers.*]
29+
strict_optional = False
30+
31+
# Various internal modules that typeshed deliberately doesn't have stubs for:
32+
[mypy-_abc.*,_opcode.*,_overlapped.*,_testcapi.*,_testinternalcapi.*,test.*]
33+
ignore_missing_imports = True

Lib/test/libregrtest/results.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def accumulate_result(self, result: TestResult, runtests: RunTests):
114114
self.worker_bug = True
115115

116116
if result.has_meaningful_duration() and not rerun:
117+
if result.duration is None:
118+
raise ValueError("result.duration is None")
117119
self.test_times.append((result.duration, test_name))
118120
if result.stats is not None:
119121
self.stats.accumulate(result.stats)

Lib/test/libregrtest/single.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ def _runtest(result: TestResult, runtests: RunTests) -> None:
237237
output_on_failure = runtests.output_on_failure
238238
timeout = runtests.timeout
239239

240-
use_timeout = (
241-
timeout is not None and threading_helper.can_start_thread
242-
)
243-
if use_timeout:
240+
if timeout is not None and threading_helper.can_start_thread:
241+
use_timeout = True
244242
faulthandler.dump_traceback_later(timeout, exit=True)
243+
else:
244+
use_timeout = False
245245

246246
try:
247247
setup_tests(runtests)

Lib/test/libregrtest/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,19 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
377377
# Python out of the source tree, especially when the
378378
# source tree is read only.
379379
tmp_dir = sysconfig.get_config_var('srcdir')
380+
if not tmp_dir:
381+
raise RuntimeError(
382+
"Could not determine the correct value for tmp_dir"
383+
)
380384
tmp_dir = os.path.join(tmp_dir, 'build')
381385
else:
382386
# WASI platform
383387
tmp_dir = sysconfig.get_config_var('projectbase')
388+
if not tmp_dir:
389+
raise RuntimeError(
390+
"sysconfig.get_config_var('projectbase') "
391+
f"unexpectedly returned {tmp_dir!r} on WASI"
392+
)
384393
tmp_dir = os.path.join(tmp_dir, 'build')
385394

386395
# When get_temp_dir() is called in a worker process,

0 commit comments

Comments
 (0)