Skip to content

Commit 8f608f8

Browse files
authored
chore: add mypy to the build (#689)
The method used here follows the same pattern that SQLAlchemy has been using to add types. For an example, see https://github.com/sqlalchemy/sqlalchemy/pull/9039/files and note the removal of the `# mypy: ignore-errors` comment to incrementally add types.
1 parent 491cab3 commit 8f608f8

File tree

4 files changed

+136
-3
lines changed

4 files changed

+136
-3
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Code check
4242
run: tox -e ${TOX_VENV}
4343
env:
44-
TOX_VENV: black,pep8
44+
TOX_VENV: black,pep8,mypy
4545

4646
test:
4747
needs: [validate]

pyproject.toml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,125 @@ extend-exclude = '''
2121

2222
[tool.pytest.ini_options]
2323
addopts = "-ra -v"
24+
25+
[tool.mypy]
26+
27+
# For details on each flag, please see the mypy documentation at:
28+
# https://mypy.readthedocs.io/en/stable/config_file.html#config-file
29+
30+
# Note: The order of flags listed here should match the order used in mypy's
31+
# documentation to make it easier to find the documentation for each flag.
32+
33+
# Import Discovery
34+
ignore_missing_imports = false
35+
36+
# Disallow dynamic typing
37+
disallow_any_unimported = true
38+
disallow_any_expr = false
39+
disallow_any_decorated = true
40+
disallow_any_explicit = true
41+
disallow_any_generics = true
42+
disallow_subclassing_any = true
43+
44+
# Untyped definitions and calls
45+
disallow_untyped_calls = true
46+
disallow_untyped_defs = true
47+
disallow_incomplete_defs = true
48+
check_untyped_defs = true
49+
disallow_untyped_decorators = true
50+
51+
# None and Optional handling
52+
implicit_optional = false
53+
strict_optional = true
54+
55+
# Configuring warnings
56+
warn_redundant_casts = true
57+
warn_unused_ignores = true
58+
warn_no_return = true
59+
warn_return_any = true
60+
warn_unreachable = true
61+
62+
# Miscellaneous strictness flags
63+
allow_untyped_globals = false
64+
allow_redefinition = false
65+
local_partial_types = true
66+
implicit_reexport = false
67+
strict_concatenate = true
68+
strict_equality = true
69+
strict = true
70+
71+
# Configuring error messages
72+
show_error_context = true
73+
show_column_numbers = true
74+
hide_error_codes = false
75+
pretty = true
76+
color_output = true
77+
error_summary = true
78+
show_absolute_path = true
79+
80+
# Miscellaneous
81+
warn_unused_configs = true
82+
verbosity = 0
83+
84+
# FIXME: As type annotations are introduced, please remove the appropriate
85+
# ignore_errors flag below. New modules should NOT be added here!
86+
87+
[[tool.mypy.overrides]]
88+
module = [
89+
'kazoo.client',
90+
'kazoo.exceptions',
91+
'kazoo.handlers.eventlet',
92+
'kazoo.handlers.gevent',
93+
'kazoo.handlers.threading',
94+
'kazoo.handlers.utils',
95+
'kazoo.hosts',
96+
'kazoo.interfaces',
97+
'kazoo.loggingsupport',
98+
'kazoo.protocol.connection',
99+
'kazoo.protocol.paths',
100+
'kazoo.protocol.serialization',
101+
'kazoo.protocol.states',
102+
'kazoo.recipe.barrier',
103+
'kazoo.recipe.cache',
104+
'kazoo.recipe.counter',
105+
'kazoo.recipe.election',
106+
'kazoo.recipe.lease',
107+
'kazoo.recipe.lock',
108+
'kazoo.recipe.partitioner',
109+
'kazoo.recipe.party',
110+
'kazoo.recipe.queue',
111+
'kazoo.recipe.watchers',
112+
'kazoo.retry',
113+
'kazoo.security',
114+
'kazoo.testing.common',
115+
'kazoo.testing.harness',
116+
'kazoo.tests.conftest',
117+
'kazoo.tests.test__connection',
118+
'kazoo.tests.test_barrier',
119+
'kazoo.tests.test_build',
120+
'kazoo.tests.test_cache',
121+
'kazoo.tests.test_client',
122+
'kazoo.tests.test_counter',
123+
'kazoo.tests.test_election',
124+
'kazoo.tests.test_eventlet_handler',
125+
'kazoo.tests.test_exceptions',
126+
'kazoo.tests.test_gevent_handler',
127+
'kazoo.tests.test_hosts',
128+
'kazoo.tests.test_interrupt',
129+
'kazoo.tests.test_lease',
130+
'kazoo.tests.test_lock',
131+
'kazoo.tests.test_partitioner',
132+
'kazoo.tests.test_party',
133+
'kazoo.tests.test_paths',
134+
'kazoo.tests.test_queue',
135+
'kazoo.tests.test_retry',
136+
'kazoo.tests.test_sasl',
137+
'kazoo.tests.test_security',
138+
'kazoo.tests.test_selectors_select',
139+
'kazoo.tests.test_threading_handler',
140+
'kazoo.tests.test_utils',
141+
'kazoo.tests.test_watchers',
142+
'kazoo.tests.util',
143+
'kazoo.version'
144+
]
145+
ignore_errors = true

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ sasl =
7373
docs =
7474
Sphinx>=1.2.2
7575

76+
typing =
77+
mypy>=0.991
78+
7679
alldeps =
7780
%(dev)s
7881
%(eventlet)s
7982
%(gevent)s
8083
%(sasl)s
8184
%(docs)s
82-
85+
%(typing)s
8386

tox.ini

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires=
44
virtualenv>=20.7.2
55
skip_missing_interpreters=True
66
envlist =
7-
pep8,black,
7+
pep8,black,mypy,
88
gevent,eventlet,sasl,
99
docs,
1010
pypy3
@@ -59,3 +59,11 @@ deps =
5959
usedevelop = True
6060
commands = black --check {posargs: {toxinidir}/kazoo {toxinidir}/kazoo}
6161

62+
[testenv:mypy]
63+
basepython = python3
64+
extras = alldeps
65+
deps =
66+
mypy
67+
mypy: types-mock
68+
usedevelop = True
69+
commands = mypy --config-file {toxinidir}/pyproject.toml {toxinidir}/kazoo

0 commit comments

Comments
 (0)