Skip to content

Commit a1d6451

Browse files
committed
docs: add types to recipe.election
1 parent 4b13135 commit a1d6451

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

kazoo/recipe/election.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
"""
77
from kazoo.exceptions import CancelledError
88

9+
from typing import TYPE_CHECKING, Callable, List, Optional
10+
11+
if TYPE_CHECKING:
12+
from kazoo.client import KazooClient
13+
from typing_extensions import ParamSpec
14+
15+
P = ParamSpec("P")
16+
917

1018
class Election(object):
1119
"""Kazoo Basic Leader Election
@@ -22,7 +30,9 @@ class Election(object):
2230
2331
"""
2432

25-
def __init__(self, client, path, identifier=None):
33+
def __init__(
34+
self, client: KazooClient, path: str, identifier: Optional[str] = None
35+
):
2636
"""Create a Kazoo Leader Election
2737
2838
:param client: A :class:`~kazoo.client.KazooClient` instance.
@@ -34,7 +44,9 @@ def __init__(self, client, path, identifier=None):
3444
"""
3545
self.lock = client.Lock(path, identifier)
3646

37-
def run(self, func, *args, **kwargs):
47+
def run(
48+
self, func: Callable[P, None], *args: P.args, **kwargs: P.kwargs
49+
) -> None:
3850
"""Contend for the leadership
3951
4052
This call will block until either this contender is cancelled
@@ -57,7 +69,7 @@ def run(self, func, *args, **kwargs):
5769
except CancelledError:
5870
pass
5971

60-
def cancel(self):
72+
def cancel(self) -> None:
6173
"""Cancel participation in the election
6274
6375
.. note::
@@ -68,7 +80,7 @@ def cancel(self):
6880
"""
6981
self.lock.cancel()
7082

71-
def contenders(self):
83+
def contenders(self) -> List[str]:
7284
"""Return an ordered list of the current contenders in the
7385
election
7486

pyproject.toml

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

2222
[tool.pytest.ini_options]
2323
addopts = "-ra -v"
24+
25+
[tool.mypy]
26+
strict = true
27+
python_version = "3.7"
28+
follow_imports = "silent"
29+
ignore_missing_imports = true
30+
disable_error_code = ["no-untyped-call", "no-untyped-def"]
31+
files = [
32+
"kazoo/recipe/election.py"
33+
]
34+
35+
[[tool.mypy.overrides]]
36+
module = 'kazoo.tests.*'
37+
ignore_errors = true
38+
39+
[[tool.mypy.overrides]]
40+
module = 'gevent.*'
41+
ignore_missing_imports = true
42+
43+
[[tool.mypy.overrides]]
44+
module = 'eventlet.*'
45+
ignore_missing_imports = true
46+
47+
[[tool.mypy.overrides]]
48+
module = 'puresasl.*'
49+
ignore_missing_imports = true

0 commit comments

Comments
 (0)