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: libregrtest: enable mypy's --strict-optional check on most files #112586

Merged
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
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):

self.interrupted: bool = False
self.worker_bug: bool = False
self.test_times: list[tuple[float, TestName]] = []
self.test_times: list[tuple[float | None, TestName]] = []
self.stats = TestStats()
# used by --junit-xml
self.testsuite_xml: list = []
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class RunTests:
python_cmd: tuple[str, ...] | None
randomize: bool
random_seed: int | str
json_file: JsonFile | None
json_file: JsonFile
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

def copy(self, **override):
state = dataclasses.asdict(self)
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/libregrtest/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved

try:
setup_tests(runtests)
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 tmp_dir is None:
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
raise RuntimeError(
"sysconfig.get_config_var('projectbase') "
"unexpectedly returned `None` on WASI"
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
)
tmp_dir = os.path.join(tmp_dir, 'build')

# When get_temp_dir() is called in a worker process,
Expand Down
Loading