Skip to content

Commit 410b890

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

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

kazoo/recipe/election.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@
44
:Status: Unknown
55
66
"""
7+
from __future__ import annotations
8+
9+
from typing import TYPE_CHECKING
10+
711
from kazoo.exceptions import CancelledError
812

13+
if TYPE_CHECKING:
14+
from kazoo.client import KazooClient
15+
from typing import Callable, List, Optional
16+
from typing_extensions import ParamSpec
17+
18+
P = ParamSpec("P")
19+
920

1021
class Election(object):
1122
"""Kazoo Basic Leader Election
@@ -22,7 +33,9 @@ class Election(object):
2233
2334
"""
2435

25-
def __init__(self, client, path, identifier=None):
36+
def __init__(
37+
self, client: KazooClient, path: str, identifier: Optional[str] = None
38+
):
2639
"""Create a Kazoo Leader Election
2740
2841
:param client: A :class:`~kazoo.client.KazooClient` instance.
@@ -34,7 +47,9 @@ def __init__(self, client, path, identifier=None):
3447
"""
3548
self.lock = client.Lock(path, identifier)
3649

37-
def run(self, func, *args, **kwargs):
50+
def run(
51+
self, func: Callable[P, None], *args: P.args, **kwargs: P.kwargs
52+
) -> None:
3853
"""Contend for the leadership
3954
4055
This call will block until either this contender is cancelled
@@ -57,7 +72,7 @@ def run(self, func, *args, **kwargs):
5772
except CancelledError:
5873
pass
5974

60-
def cancel(self):
75+
def cancel(self) -> None:
6176
"""Cancel participation in the election
6277
6378
.. note::
@@ -68,7 +83,7 @@ def cancel(self):
6883
"""
6984
self.lock.cancel()
7085

71-
def contenders(self):
86+
def contenders(self) -> List[str]:
7287
"""Return an ordered list of the current contenders in the
7388
election
7489

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)