Skip to content

Commit 37d2198

Browse files
committed
Add basic mypy linting
Based on pytest setup, though more lax. Currently only the tests are annotated so only helpful for them. Fix pytest-dev#721.
1 parent 545df8e commit 37d2198

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ repos:
2828
files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst|changelog/.*)$
2929
language: python
3030
additional_dependencies: [pygments, restructuredtext_lint]
31+
- repo: https://github.com/pre-commit/mirrors-mypy
32+
rev: v0.910-1
33+
hooks:
34+
- id: mypy
35+
files: ^(src/|testing/)
36+
args: []
37+
additional_dependencies:
38+
- pytest>=6.2.0
39+
- py>=1.10.0

changelog/721.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Started using type annotations and mypy checking internally. The types are incomplete and not published.

setup.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,17 @@ setproctitle = setproctitle
5959

6060
[flake8]
6161
max-line-length = 100
62+
63+
[mypy]
64+
mypy_path = src
65+
# check_untyped_defs = True
66+
disallow_any_generics = True
67+
ignore_missing_imports = True
68+
no_implicit_optional = True
69+
show_error_codes = True
70+
strict_equality = True
71+
warn_redundant_casts = True
72+
warn_return_any = True
73+
warn_unreachable = True
74+
warn_unused_configs = True
75+
# no_implicit_reexport = True

src/xdist/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def is_xdist_controller(request_or_session) -> bool:
250250
is_xdist_master = is_xdist_controller
251251

252252

253-
def get_xdist_worker_id(request_or_session) -> str:
253+
def get_xdist_worker_id(request_or_session):
254254
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
255255
if running on the controller node.
256256

src/xdist/remote.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def setup_config(config, basetemp):
236236

237237

238238
if __name__ == "__channelexec__":
239-
channel = channel # noqa
240-
workerinput, args, option_dict, change_sys_path = channel.receive()
239+
channel = channel # type: ignore[name-defined] # noqa: F821
240+
workerinput, args, option_dict, change_sys_path = channel.receive() # type: ignore[name-defined]
241241

242242
if change_sys_path is None:
243243
importpath = os.getcwd()
@@ -260,7 +260,7 @@ def setup_config(config, basetemp):
260260

261261
setup_config(config, option_dict.get("basetemp"))
262262
config._parser.prog = os.path.basename(workerinput["mainargv"][0])
263-
config.workerinput = workerinput
264-
config.workeroutput = {}
265-
interactor = WorkerInteractor(config, channel)
263+
config.workerinput = workerinput # type: ignore[attr-defined]
264+
config.workeroutput = {} # type: ignore[attr-defined]
265+
interactor = WorkerInteractor(config, channel) # type: ignore[name-defined]
266266
config.hook.pytest_cmdline_main(config=config)

0 commit comments

Comments
 (0)