2121"""
2222from abc import ABC , abstractmethod
2323from numbers import Number
24+ from typing import Union , Any
25+
2426
2527class FilterCondition (ABC ):
2628 """
@@ -31,7 +33,7 @@ class FilterCondition(ABC):
3133 segment=filter({'my_annotation': <FilterCondition>})
3234 """
3335 @abstractmethod
34- def __init__ (self , z ):
36+ def __init__ (self , z ) -> None :
3537 """
3638 Initialize new FilterCondition object.
3739
@@ -60,82 +62,82 @@ class Equals(FilterCondition):
6062 """
6163 Filter condition to check if target value is equal to the control value.
6264 """
63- def __init__ (self , z ) :
65+ def __init__ (self , z : Any ) -> None :
6466 self .control = z
6567
66- def evaluate (self , x ) :
68+ def evaluate (self , x : Any ) -> bool :
6769 return x == self .control
6870
6971
7072class IsNot (FilterCondition ):
7173 """
7274 Filter condition to check if target value is not equal to the control value.
7375 """
74- def __init__ (self , z ) :
76+ def __init__ (self , z : Any ) -> None :
7577 self .control = z
7678
77- def evaluate (self , x ) :
79+ def evaluate (self , x : Any ) -> bool :
7880 return x != self .control
7981
8082
8183class LessThanOrEquals (FilterCondition ):
8284 """
8385 Filter condition to check if target value is less than or equal to the control value.
8486 """
85- def __init__ (self , z ) :
87+ def __init__ (self , z : Number ) -> None :
8688 self .control = z
8789
88- def evaluate (self , x ) :
90+ def evaluate (self , x : Number ) -> bool :
8991 return x <= self .control
9092
9193
9294class GreaterThanOrEquals (FilterCondition ):
9395 """
9496 Filter condition to check if target value is greater than or equal to the control value.
9597 """
96- def __init__ (self , z ) :
98+ def __init__ (self , z : Number ) -> None :
9799 self .control = z
98100
99- def evaluate (self , x ) :
101+ def evaluate (self , x : Number ) -> bool :
100102 return x >= self .control
101103
102104
103105class LessThan (FilterCondition ):
104106 """
105107 Filter condition to check if target value is less than the control value.
106108 """
107- def __init__ (self , z ) :
109+ def __init__ (self , z : Number ) -> None :
108110 self .control = z
109111
110- def evaluate (self , x ) :
112+ def evaluate (self , x : Number ) -> bool :
111113 return x < self .control
112114
113115
114116class GreaterThan (FilterCondition ):
115117 """
116118 Filter condition to check if target value is greater than the control value.
117119 """
118- def __init__ (self , z ) :
120+ def __init__ (self , z : Number ) -> None :
119121 self .control = z
120122
121- def evaluate (self , x ) :
123+ def evaluate (self , x : Number ) -> bool :
122124 return x > self .control
123125
124126
125127class IsIn (FilterCondition ):
126128 """
127129 Filter condition to check if target is in control.
128130 """
129- def __init__ (self , z ) :
131+ def __init__ (self , z : Union [ list , tuple , set , int ]) -> None :
130132 self .control = z
131133
132- def evaluate (self , x ) :
134+ def evaluate (self , x : Any ) -> bool :
133135 if isinstance (self .control , (list , tuple , set )):
134136 return x in self .control
135137 if isinstance (self .control , int ):
136138 return x == self .control
137139
138- raise SyntaxError ('parameter not of type list or int' )
140+ raise SyntaxError ('parameter not of type list, tuple, set or int' )
139141
140142
141143class InRange (FilterCondition ):
@@ -151,7 +153,8 @@ class InRange(FilterCondition):
151153 left_closed: bool - If True, the range includes the lower bound (lower_bound <= x).
152154 right_closed: bool - If True, the range includes the upper bound (x <= upper_bound).
153155 """
154- def __init__ (self , lower_bound , upper_bound , left_closed = False , right_closed = False ):
156+ def __init__ (self , lower_bound : Number , upper_bound : Number ,
157+ left_closed : bool = False , right_closed : bool = False ) -> None :
155158 if not isinstance (lower_bound , Number ) or not isinstance (upper_bound , Number ):
156159 raise ValueError ("parameter is not a number" )
157160
@@ -160,7 +163,7 @@ def __init__(self, lower_bound, upper_bound, left_closed=False, right_closed=Fal
160163 self .left_closed = left_closed
161164 self .right_closed = right_closed
162165
163- def evaluate (self , x ) :
166+ def evaluate (self , x : Number ) -> bool :
164167 if not self .left_closed and not self .right_closed :
165168 return self .lower_bound <= x <= self .upper_bound
166169 if not self .left_closed and self .right_closed :
0 commit comments