6
6
"""
7
7
from kazoo .exceptions import CancelledError
8
8
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
+
9
17
10
18
class Election (object ):
11
19
"""Kazoo Basic Leader Election
@@ -22,7 +30,9 @@ class Election(object):
22
30
23
31
"""
24
32
25
- def __init__ (self , client , path , identifier = None ):
33
+ def __init__ (
34
+ self , client : KazooClient , path : str , identifier : Optional [str ] = None
35
+ ):
26
36
"""Create a Kazoo Leader Election
27
37
28
38
:param client: A :class:`~kazoo.client.KazooClient` instance.
@@ -34,7 +44,9 @@ def __init__(self, client, path, identifier=None):
34
44
"""
35
45
self .lock = client .Lock (path , identifier )
36
46
37
- def run (self , func , * args , ** kwargs ):
47
+ def run (
48
+ self , func : Callable [P , None ], * args : P .args , ** kwargs : P .kwargs
49
+ ) -> None :
38
50
"""Contend for the leadership
39
51
40
52
This call will block until either this contender is cancelled
@@ -57,7 +69,7 @@ def run(self, func, *args, **kwargs):
57
69
except CancelledError :
58
70
pass
59
71
60
- def cancel (self ):
72
+ def cancel (self ) -> None :
61
73
"""Cancel participation in the election
62
74
63
75
.. note::
@@ -68,7 +80,7 @@ def cancel(self):
68
80
"""
69
81
self .lock .cancel ()
70
82
71
- def contenders (self ):
83
+ def contenders (self ) -> List [ str ] :
72
84
"""Return an ordered list of the current contenders in the
73
85
election
74
86
0 commit comments