8000 gh-109413: libregrtest: enable mypy's `--strict-optional` check on mo… · python/cpython@1407526 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1407526

Browse files
AlexWaygoodvstinner
authored andcommitted
gh-109413: libregrtest: enable mypy's --strict-optional check on most files (#112586)
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 8ec266e commit 1407526

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

Lib/test/libregrtest/mypy.ini

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

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)
0