]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] [3.12] gh-109413: libregrtest: enable mypy's `--strict-optional` check on...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 1 Dec 2023 17:28:09 +0000 (18:28 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Dec 2023 17:28:09 +0000 (17:28 +0000)
[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 36dbebed44785579034ffb1a59f0a1a5b987c9bf)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/libregrtest/mypy.ini [new file with mode: 0644]
Lib/test/libregrtest/results.py
Lib/test/libregrtest/single.py
Lib/test/libregrtest/utils.py

diff --git a/Lib/test/libregrtest/mypy.ini b/Lib/test/libregrtest/mypy.ini
new file mode 100644 (file)
index 0000000..22c7c7a
--- /dev/null
@@ -0,0 +1,33 @@
+# Config file for running mypy on libregrtest.
+# Run mypy by invoking `mypy --config-file Lib/test/libregrtest/mypy.ini`
+# on the command-line from the repo root
+
+[mypy]
+files = Lib/test/libregrtest
+explicit_package_bases = True
+python_version = 3.12
+platform = linux
+pretty = True
+
+# Enable most stricter settings
+enable_error_code = ignore-without-code
+strict = True
+
+# Various stricter settings that we can't yet enable
+# Try to enable these in the following order:
+disallow_any_generics = False
+disallow_incomplete_defs = False
+disallow_untyped_calls = False
+disallow_untyped_defs = False
+check_untyped_defs = False
+warn_return_any = False
+
+disable_error_code = return
+
+# Enable --strict-optional for these ASAP:
+[mypy-Lib.test.libregrtest.main.*,Lib.test.libregrtest.run_workers.*]
+strict_optional = False
+
+# Various internal modules that typeshed deliberately doesn't have stubs for:
+[mypy-_abc.*,_opcode.*,_overlapped.*,_testcapi.*,_testinternalcapi.*,test.*]
+ignore_missing_imports = True
index 1feb43f8c074db6a4d4fecc68137844dd1476c46..ad1744899cadc08d4b0e3063a60069c148cf2177 100644 (file)
@@ -114,6 +114,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 25f3e853137316741fcefd357d75cbb0ec53a2f1..5eb2d72186b2e6860bf28bfd241232287fa6308d 100644 (file)
@@ -372,10 +372,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,