From 787b8d9c14ca663d95632e43d55adcc4c76058c7 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 30 Oct 2021 12:18:11 +0300 Subject: [PATCH] Add basic mypy linting Based on pytest setup, though more lax. Currently only the tests are annotated so only helpful for them. Fix #721. --- .pre-commit-config.yaml | 9 +++++++++ changelog/721.trivial.rst | 1 + setup.cfg | 16 ++++++++++++++++ src/xdist/plugin.py | 2 +- src/xdist/remote.py | 10 +++++----- 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 changelog/721.trivial.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43a0578..b1dda8a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,12 @@ repos: files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst|changelog/.*)$ language: python additional_dependencies: [pygments, restructuredtext_lint] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910-1 + hooks: + - id: mypy + files: ^(src/|testing/) + args: [] + additional_dependencies: + - pytest>=6.2.0 + - py>=1.10.0 diff --git a/changelog/721.trivial.rst b/changelog/721.trivial.rst new file mode 100644 index 0000000..1c32376 --- /dev/null +++ b/changelog/721.trivial.rst @@ -0,0 +1 @@ +Started using type annotations and mypy checking internally. The types are incomplete and not published. diff --git a/setup.cfg b/setup.cfg index d09d11a..ce97d81 100644 --- a/setup.cfg +++ b/setup.cfg @@ -58,3 +58,19 @@ setproctitle = setproctitle [flake8] max-line-length = 100 + +[mypy] +mypy_path = src +# TODO: Enable this & fix errors. +# check_untyped_defs = True +disallow_any_generics = True +ignore_missing_imports = True +no_implicit_optional = True +show_error_codes = True +strict_equality = True +warn_redundant_casts = True +warn_return_any = True +warn_unreachable = True +warn_unused_configs = True +# TODO: Enable this & fix errors. +# no_implicit_reexport = True diff --git a/src/xdist/plugin.py b/src/xdist/plugin.py index 12b3a0e..4f410cc 100644 --- a/src/xdist/plugin.py +++ b/src/xdist/plugin.py @@ -250,7 +250,7 @@ def is_xdist_controller(request_or_session) -> bool: is_xdist_master = is_xdist_controller -def get_xdist_worker_id(request_or_session) -> str: +def get_xdist_worker_id(request_or_session): """Return the id of the current worker ('gw0', 'gw1', etc) or 'master' if running on the controller node. diff --git a/src/xdist/remote.py b/src/xdist/remote.py index 0194ae0..05951f3 100644 --- a/src/xdist/remote.py +++ b/src/xdist/remote.py @@ -236,8 +236,8 @@ def setup_config(config, basetemp): if __name__ == "__channelexec__": - channel = channel # noqa - workerinput, args, option_dict, change_sys_path = channel.receive() + channel = channel # type: ignore[name-defined] # noqa: F821 + workerinput, args, option_dict, change_sys_path = channel.receive() # type: ignore[name-defined] if change_sys_path is None: importpath = os.getcwd() @@ -260,7 +260,7 @@ if __name__ == "__channelexec__": setup_config(config, option_dict.get("basetemp")) config._parser.prog = os.path.basename(workerinput["mainargv"][0]) - config.workerinput = workerinput - config.workeroutput = {} - interactor = WorkerInteractor(config, channel) + config.workerinput = workerinput # type: ignore[attr-defined] + config.workeroutput = {} # type: ignore[attr-defined] + interactor = WorkerInteractor(config, channel) # type: ignore[name-defined] config.hook.pytest_cmdline_main(config=config)