Skip to content

Commit 3f81fa5

Browse files
committed
docs: add types to recipe.election
1 parent 56569a6 commit 3f81fa5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

kazoo/recipe/election.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
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')
916

1017
class Election(object):
1118
"""Kazoo Basic Leader Election
@@ -22,7 +29,7 @@ class Election(object):
2229
2330
"""
2431

25-
def __init__(self, client, path, identifier=None):
32+
def __init__(self, client: KazooClient, path: str, identifier: Optional[str]=None):
2633
"""Create a Kazoo Leader Election
2734
2835
:param client: A :class:`~kazoo.client.KazooClient` instance.
@@ -34,7 +41,7 @@ def __init__(self, client, path, identifier=None):
3441
"""
3542
self.lock = client.Lock(path, identifier)
3643

37-
def run(self, func, *args, **kwargs):
44+
def run(self, func: Callable[P, None], *args: P.args, **kwargs: P.kwargs) -> None:
3845
"""Contend for the leadership
3946
4047
This call will block until either this contender is cancelled
@@ -57,7 +64,7 @@ def run(self, func, *args, **kwargs):
5764
except CancelledError:
5865
pass
5966

60-
def cancel(self):
67+
def cancel(self) -> None:
6168
"""Cancel participation in the election
6269
6370
.. note::
@@ -68,7 +75,7 @@ def cancel(self):
6875
"""
6976
self.lock.cancel()
7077

71-
def contenders(self):
78+
def contenders(self) -> List[str]:
7279
"""Return an ordered list of the current contenders in the
7380
election
7481

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)