]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-109413: Enable `strict_optional` for `libregrtest/main.py` (GH-126394)...
authorsobolevn <mail@sobolevn.me>
Thu, 14 Nov 2024 10:51:34 +0000 (13:51 +0300)
committerGitHub <noreply@github.com>
Thu, 14 Nov 2024 10:51:34 +0000 (13:51 +0300)
(cherry picked from commit 12ca7e622ff21ba3b7c90c62be6f6f82d543f25b)

Lib/test/libregrtest/cmdline.py
Lib/test/libregrtest/main.py
Lib/test/libregrtest/mypy.ini
Lib/test/libregrtest/run_workers.py

index 8bef04cba811388f7d02c3102e95c8746df13756..0c94fcc190707114c1411f8e48230b1e2f6c05ca 100644 (file)
@@ -148,7 +148,7 @@ class Namespace(argparse.Namespace):
         self.randomize = False
         self.fromfile = None
         self.fail_env_changed = False
-        self.use_resources = None
+        self.use_resources: list[str] = []
         self.trace = False
         self.coverdir = 'coverage'
         self.runleaks = False
@@ -403,8 +403,6 @@ def _parse_args(args, **kwargs):
             raise TypeError('%r is an invalid keyword argument '
                             'for this function' % k)
         setattr(ns, k, v)
-    if ns.use_resources is None:
-        ns.use_resources = []
 
     parser = _create_parser()
     # Issue #14191: argparse doesn't support "intermixed" positional and
index fc2244ee743e9526566a3db7a2a74b9f4e47b795..36c45586db1b17315aea3c32ae66daef4fa0c1bd 100644 (file)
@@ -123,7 +123,7 @@ class Regrtest:
             self.python_cmd = None
         self.coverage: bool = ns.trace
         self.coverage_dir: StrPath | None = ns.coverdir
-        self.tmp_dir: StrPath | None = ns.tempdir
+        self._tmp_dir: StrPath | None = ns.tempdir
 
         # Randomize
         self.randomize: bool = ns.randomize
@@ -159,6 +159,8 @@ class Regrtest:
         self.logger.log(line)
 
     def find_tests(self, tests: TestList | None = None) -> tuple[TestTuple, TestList | None]:
+        if tests is None:
+            tests = []
         if self.single_test_run:
             self.next_single_filename = os.path.join(self.tmp_dir, 'pynexttest')
             try:
@@ -453,7 +455,12 @@ class Regrtest:
         if self.junit_filename:
             self.results.write_junit(self.junit_filename)
 
-    def display_summary(self):
+    def display_summary(self) -> None:
+        if self.first_runtests is None:
+            raise ValueError(
+                "Should never call `display_summary()` before calling `_run_test()`"
+            )
+
         duration = time.perf_counter() - self.logger.start_time
         filtered = bool(self.match_tests)
 
@@ -711,7 +718,15 @@ class Regrtest:
 
         strip_py_suffix(self.cmdline_args)
 
-        self.tmp_dir = get_temp_dir(self.tmp_dir)
+        self._tmp_dir = get_temp_dir(self._tmp_dir)
+
+    @property
+    def tmp_dir(self) -> StrPath:
+        if self._tmp_dir is None:
+            raise ValueError(
+                "Should never use `.tmp_dir` before calling `.main()`"
+            )
+        return self._tmp_dir
 
     def main(self, tests: TestList | None = None):
         if self.want_add_python_opts:
index 22c7c7a9acef1480b4a3165ef1057d58ca80bdc9..da75a27158a600380146a48742e4e376c22ae3b4 100644 (file)
@@ -22,10 +22,8 @@ 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.*]
+[mypy-Lib.test.libregrtest.run_workers.*]
 strict_optional = False
 
 # Various internal modules that typeshed deliberately doesn't have stubs for:
index 235047cf2e563caa06492b2b74157575e56355aa..263bedf01508610023b8e2074b82949ed4458d75 100644 (file)
@@ -205,6 +205,7 @@ class WorkerThread(threading.Thread):
                     # on reading closed stdout
                     raise ExitThread
                 raise
+            return None
         except:
             self._kill()
             raise
@@ -538,6 +539,7 @@ class RunWorkers:
                 running = get_running(self.workers)
                 if running:
                     self.log(running)
+        return None
 
     def display_result(self, mp_result: MultiprocessResult) -> None:
         result = mp_result.result