Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-109413: libregrtest: Add and improve type annotations#109405
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
86a0f2f51bf6779ce367ead6b96a28ad940f8c64eeFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Config file for running mypy on libregrtest. | ||
| # | ||
| # Note: mypy can't be run on libregrtest from the CPython repo root. | ||
| # If you try to do so, mypy will complain | ||
| # about the entire `Lib/` directory "shadowing the stdlib". | ||
| # Instead, `cd` into `Lib/test`, then run `mypy --config-file libregrtest/mypy.ini`. | ||
| [mypy] | ||
| packages = libregrtest | ||
| python_version = 3.11 | ||
| 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: | ||
| strict_optional = False | ||
| 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 | ||
| # Various internal modules that typeshed deliberately doesn't have stubs for: | ||
| [mypy-_abc.*] | ||
| ignore_missing_imports = True | ||
| [mypy-_opcode.*] | ||
| ignore_missing_imports = True | ||
| [mypy-_overlapped.*] | ||
| ignore_missing_imports = True | ||
| [mypy-_testcapi.*] | ||
| ignore_missing_imports = True | ||
| [mypy-_testinternalcapi.*] | ||
| ignore_missing_imports = True | ||
| [mypy-test.*] | ||
| ignore_missing_imports = True |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,7 +21,7 @@ | ||
| from .runtests import RunTests, JsonFile, JsonFileType | ||
| from .single import PROGRESS_MIN_TIME | ||
| from .utils import ( | ||
| StrPath, StrJSON, TestName, MS_WINDOWS, | ||
| StrPath, TestName, MS_WINDOWS, | ||
| format_duration, print_warning, count, plural) | ||
| from .worker import create_worker_process, USE_PROCESS_GROUP | ||
| @@ -104,9 +104,9 @@ def __init__(self, worker_id: int, runner: "RunWorkers") -> None: | ||
| self.output = runner.output | ||
| self.timeout = runner.worker_timeout | ||
| self.log = runner.log | ||
| self.test_name = None | ||
| self.start_time = None | ||
| self._popen = None | ||
| self.test_name: TestName | None = None | ||
| self.start_time: float | None = None | ||
| self._popen: subprocess.Popen[str] | None = None | ||
AlexWaygood marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| self._killed = False | ||
| self._stopped = False | ||
| @@ -160,7 +160,7 @@ def stop(self) -> None: | ||
| self._kill() | ||
| def _run_process(self, runtests: RunTests, output_fd: int, | ||
| tmp_dir: StrPath | None = None) -> int: | ||
| tmp_dir: StrPath | None = None) -> int | None: | ||
| popen = create_worker_process(runtests, output_fd, tmp_dir) | ||
| self._popen = popen | ||
| self._killed = False | ||
| @@ -260,7 +260,7 @@ def create_worker_runtests(self, test_name: TestName, json_file: JsonFile) -> Ru | ||
| **kwargs) | ||
| def run_tmp_files(self, worker_runtests: RunTests, | ||
| stdout_fd: int) -> (int, list[StrPath]): | ||
| stdout_fd: int) -> tuple[int | None, list[StrPath]]: | ||
| # gh-93353: Check for leaked temporary files in the parent process, | ||
| # since the deletion of temporary files can happen late during | ||
| # Python finalization: too late for libregrtest. | ||
| @@ -297,13 +297,13 @@ def read_json(self, json_file: JsonFile, json_tmpfile: TextIO | None, | ||
| try: | ||
| if json_tmpfile is not None: | ||
| json_tmpfile.seek(0) | ||
| worker_json: StrJSON = json_tmpfile.read() | ||
AlexWaygood marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| worker_json = json_tmpfile.read() | ||
| elif json_file.file_type == JsonFileType.STDOUT: | ||
| stdout, _, worker_json = stdout.rpartition("\n") | ||
| stdout = stdout.rstrip() | ||
| else: | ||
| with json_file.open(encoding='utf8') as json_fp: | ||
| worker_json: StrJSON = json_fp.read() | ||
| worker_json = json_fp.read() | ||
AlexWaygood marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| except Exception as exc: | ||
| # gh-101634: Catch UnicodeDecodeError if stdout cannot be | ||
| # decoded from encoding | ||
| @@ -414,8 +414,8 @@ def wait_stopped(self, start_time: float) -> None: | ||
| break | ||
| def get_running(workers: list[WorkerThread]) -> list[str]: | ||
| running = [] | ||
| def get_running(workers: list[WorkerThread]) -> str | None: | ||
| running: list[str] = [] | ||
| for worker in workers: | ||
| test_name = worker.test_name | ||
| if not test_name: | ||
| @@ -431,7 +431,7 @@ def get_running(workers: list[WorkerThread]) -> list[str]: | ||
| class RunWorkers: | ||
| def __init__(self, num_workers: int, runtests: RunTests, | ||
| logger: Logger, results: TestResult) -> None: | ||
| logger: Logger, results: TestResults) -> None: | ||
AlexWaygood marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| self.num_workers = num_workers | ||
| self.runtests = runtests | ||
| self.log = logger.log | ||
| @@ -446,10 +446,10 @@ def __init__(self, num_workers: int, runtests: RunTests, | ||
| # Rely on faulthandler to kill a worker process. This timouet is | ||
| # when faulthandler fails to kill a worker process. Give a maximum | ||
| # of 5 minutes to faulthandler to kill the worker. | ||
| self.worker_timeout = min(self.timeout * 1.5, self.timeout + 5 * 60) | ||
| self.worker_timeout: float | None = min(self.timeout * 1.5, self.timeout + 5 * 60) | ||
| else: | ||
| self.worker_timeout = None | ||
| self.workers = None | ||
| self.workers: list[WorkerThread] | None = None | ||
| jobs = self.runtests.get_jobs() | ||
| if jobs is not None: | ||
| @@ -529,7 +529,7 @@ def display_result(self, mp_result: MultiprocessResult) -> None: | ||
| text += f' -- {running}' | ||
| self.display_progress(self.test_index, text) | ||
| def _process_result(self, item: QueueOutput) -> bool: | ||
| def _process_result(self, item: QueueOutput) -> TestResult: | ||
| """Returns True if test runner must stop.""" | ||
| if item[0]: | ||
| # Thread got an exception | ||
Uh oh!
There was an error while loading. Please reload this page.