]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109413: libregrtest: enable mypy's `--strict-optional` check on most files (#112586)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Fri, 1 Dec 2023 14:54:33 +0000 (14:54 +0000)
committerGitHub <noreply@github.com>
Fri, 1 Dec 2023 14:54:33 +0000 (14:54 +0000)
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/libregrtest/mypy.ini
Lib/test/libregrtest/results.py
Lib/test/libregrtest/single.py
Lib/test/libregrtest/utils.py

index 331fe681b9f56b5f0e5ea82a10778bc471287bb4..22c7c7a9acef1480b4a3165ef1057d58ca80bdc9 100644 (file)
@@ -25,7 +25,7 @@ warn_return_any = False
 disable_error_code = return
 
 # Enable --strict-optional for these ASAP:
-[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.*]
+[mypy-Lib.test.libregrtest.main.*,Lib.test.libregrtest.run_workers.*]
 strict_optional = False
 
 # Various internal modules that typeshed deliberately doesn't have stubs for:
index 59a566c032847e4e0ed585c9b59db54d2db911b7..a41ea8aba028c36b65cf38974e216915a5c2ec45 100644 (file)
@@ -117,6 +117,8 @@ class TestResults:
             self.worker_bug = True
 
         if result.has_meaningful_duration() and not rerun:
+            if result.duration is None:
+                raise ValueError("result.duration is None")
             self.test_times.append((result.duration, test_name))
         if result.stats is not None:
             self.stats.accumulate(result.stats)
index 5c7bc7d40fb3945beebcb3d3580a86e4d2bd9547..eafeb5fe26f3f3a878b8be04087ccd69de5f58ad 100644 (file)
@@ -237,11 +237,11 @@ def _runtest(result: TestResult, runtests: RunTests) -> None:
     output_on_failure = runtests.output_on_failure
     timeout = runtests.timeout
 
-    use_timeout = (
-        timeout is not None and threading_helper.can_start_thread
-    )
-    if use_timeout:
+    if timeout is not None and threading_helper.can_start_thread:
+        use_timeout = True
         faulthandler.dump_traceback_later(timeout, exit=True)
+    else:
+        use_timeout = False
 
     try:
         setup_tests(runtests)
index d47e9388e62db2826690a6c49b4168ab59f43c3d..d4972ce4a50d2a16d69dc82ad3d1d296a531dad4 100644 (file)
@@ -377,10 +377,19 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
                         # Python out of the source tree, especially when the
                         # source tree is read only.
                         tmp_dir = sysconfig.get_config_var('srcdir')
+                        if not tmp_dir:
+                            raise RuntimeError(
+                                "Could not determine the correct value for tmp_dir"
+                            )
                 tmp_dir = os.path.join(tmp_dir, 'build')
             else:
                 # WASI platform
                 tmp_dir = sysconfig.get_config_var('projectbase')
+                if not tmp_dir:
+                    raise RuntimeError(
+                        "sysconfig.get_config_var('projectbase') "
+                        f"unexpectedly returned {tmp_dir!r} on WASI"
+                    )
                 tmp_dir = os.path.join(tmp_dir, 'build')
 
                 # When get_temp_dir() is called in a worker process,