Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-109413: Enable strict_optional for libregrtest/main.py #126394

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, **kwargs) -> None:
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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
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
Expand Down Expand Up @@ -159,6 +159,8 @@ def log(self, line: str = '') -> None:
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:
Expand Down Expand Up @@ -461,6 +463,7 @@ def display_summary(self) -> None:
print()
print("Total duration: %s" % format_duration(duration))

assert self.first_runtests, "self.first_runtests is None"
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
self.results.display_summary(self.first_runtests, filtered)

# Result
Expand Down Expand Up @@ -708,7 +711,12 @@ def _init(self):

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:
assert self._tmp_dir is not None, "self._tmp_dir is None"
return self._tmp_dir
sobolevn marked this conversation as resolved.
Show resolved Hide resolved

def main(self, tests: TestList | None = None) -> NoReturn:
if self.want_add_python_opts:
Expand Down
4 changes: 1 addition & 3 deletions Lib/test/libregrtest/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/libregrtest/run_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def _run_process(self, runtests: WorkerRunTests, output_fd: int,
# on reading closed stdout
raise ExitThread
raise
return None
except:
self._kill()
raise
Expand Down Expand Up @@ -544,6 +545,7 @@ def _get_result(self) -> QueueOutput | None:
running = get_running(self.workers)
if running:
self.log(running)
return None

def display_result(self, mp_result: MultiprocessResult) -> None:
result = mp_result.result
Expand Down
Loading