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