Skip to content

Commit da33204

Browse files
miss-islingtonAlexWaygoodvstinner
authored
[3.11] [3.12] gh-109413: libregrtest: enable mypy's --strict-optional check on most files (GH-112586) (GH-112602) (#112603)
[3.12] gh-109413: libregrtest: enable mypy's `--strict-optional` check on most files (GH-112586) (GH-112602) gh-109413: libregrtest: enable mypy's `--strict-optional` check on most files (GH-112586) (cherry picked from commit 36dbebe) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
1 parent 0443f92 commit da33204

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
@@ -372,10 +372,19 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
372372
# Python out of the source tree, especially when the
373373
# source tree is read only.
374374
tmp_dir = sysconfig.get_config_var('srcdir')
375+
if not tmp_dir:
376+
raise RuntimeError(
377+
"Could not determine the correct value for tmp_dir"
378+
)
375379
tmp_dir = os.path.join(tmp_dir, 'build')
376380
else:
377381
# WASI platform
378382
tmp_dir = sysconfig.get_config_var('projectbase')
383+
if not tmp_dir:
384+
raise RuntimeError(
385+
"sysconfig.get_config_var('projectbase') "
386+
f"unexpectedly returned {tmp_dir!r} on WASI"
387+
)
379388
tmp_dir = os.path.join(tmp_dir, 'build')
380389

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

0 commit comments

Comments
 (0)