1
1
import hashlib
2
+ from abc import ABC , abstractmethod
2
3
3
4
4
- class BaseDialup (object ):
5
+ class BaseDialup (ABC ):
5
6
"""BaseDialup class to provide an interface for all dialup classes"""
6
7
7
8
def __init__ (self , region_config , ** kwargs ): # type: ignore[no-untyped-def]
8
9
self .region_config = region_config
9
10
10
- def is_enabled (self ): # type: ignore[no-untyped-def]
11
+ @abstractmethod
12
+ def is_enabled (self ) -> bool :
11
13
"""
12
14
Returns a bool on whether this dialup is enabled or not
13
15
"""
14
- raise NotImplementedError
15
16
16
- def __str__ (self ): # type: ignore[no-untyped-def]
17
+ def __str__ (self ) -> str :
17
18
return self .__class__ .__name__
18
19
19
20
@@ -23,7 +24,7 @@ class DisabledDialup(BaseDialup):
23
24
"""
24
25
25
26
def __init__ (self , region_config , ** kwargs ): # type: ignore[no-untyped-def]
26
- super (DisabledDialup , self ).__init__ (region_config ) # type: ignore[no-untyped-call]
27
+ super ().__init__ (region_config ) # type: ignore[no-untyped-call]
27
28
28
29
def is_enabled (self ) -> bool :
29
30
return False
@@ -36,7 +37,7 @@ class ToggleDialup(BaseDialup):
36
37
"""
37
38
38
39
def __init__ (self , region_config , ** kwargs ): # type: ignore[no-untyped-def]
39
- super (ToggleDialup , self ).__init__ (region_config ) # type: ignore[no-untyped-call]
40
+ super ().__init__ (region_config ) # type: ignore[no-untyped-call]
40
41
self .region_config = region_config
41
42
42
43
def is_enabled (self ): # type: ignore[no-untyped-def]
@@ -50,11 +51,11 @@ class SimpleAccountPercentileDialup(BaseDialup):
50
51
"""
51
52
52
53
def __init__ (self , region_config , account_id , feature_name , ** kwargs ): # type: ignore[no-untyped-def]
53
- super (SimpleAccountPercentileDialup , self ).__init__ (region_config ) # type: ignore[no-untyped-call]
54
+ super ().__init__ (region_config ) # type: ignore[no-untyped-call]
54
55
self .account_id = account_id
55
56
self .feature_name = feature_name
56
57
57
- def _get_account_percentile (self ): # type: ignore[no-untyped-def]
58
+ def _get_account_percentile (self ) -> int :
58
59
"""
59
60
Get account percentile based on sha256 hash of account ID and feature_name
60
61
@@ -65,10 +66,10 @@ def _get_account_percentile(self): # type: ignore[no-untyped-def]
65
66
m .update (self .feature_name .encode ())
66
67
return int (m .hexdigest (), 16 ) % 100
67
68
68
- def is_enabled (self ): # type: ignore[no-untyped-def]
69
+ def is_enabled (self ) -> bool :
69
70
"""
70
71
Enable when account_percentile falls within target_percentile
71
72
Meaning only (target_percentile)% of accounts will be enabled
72
73
"""
73
- target_percentile = self .region_config .get ("enabled-%" , 0 )
74
- return self ._get_account_percentile () < target_percentile # type: ignore[no-untyped-call]
74
+ target_percentile : int = self .region_config .get ("enabled-%" , 0 )
75
+ return self ._get_account_percentile () < target_percentile
0 commit comments