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