Skip to content

Commit 70a38ff

Browse files
pythongh-109413: libregrtest: enable mypy's --strict-optional check on most files (python#112586)
Co-authored-by: Victor Stinner <[email protected]>
1 parent 5f6ac2d commit 70a38ff

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

Lib/test/libregrtest/mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ warn_return_any = False
2525
disable_error_code = return
2626

2727
# Enable --strict-optional for these ASAP:
28-
[mypy-Lib.test.libregrtest.main.*,Lib.test.libregrtest.run_workers.*,Lib.test.libregrtest.worker.*,Lib.test.libregrtest.single.*,Lib.test.libregrtest.results.*,Lib.test.libregrtest.utils.*]
28+
[mypy-Lib.test.libregrtest.main.*,Lib.test.libregrtest.run_workers.*]
2929
strict_optional = False
3030

3131
# Various internal modules that typeshed deliberately doesn't have stubs for:

Lib/test/libregrtest/results.py

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def accumulate_result(self, result: TestResult, runtests: RunTests):
117117
self.worker_bug = True
118118

119119
if result.has_meaningful_duration() and not rerun:
120+
if result.duration is None:
121+
raise ValueError("result.duration is None")
120122
self.test_times.append((result.duration, test_name))
121123
if result.stats is not None:
122124
self.stats.accumulate(result.stats)

Lib/test/libregrtest/single.py

+4-4
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

+9
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)