88import semver
99
1010from flag_engine .context .types import EvaluationContext
11- from flag_engine .identities .traits .types import TraitValue
11+ from flag_engine .identities .traits .types import ContextValue
1212from flag_engine .segments import constants
1313from flag_engine .segments .models import (
1414 SegmentConditionModel ,
@@ -104,7 +104,7 @@ def context_matches_condition(
104104 return _matches_context_value (condition , context_value ) if context_value else False
105105
106106
107- def _get_trait (context : EvaluationContext , trait_key : str ) -> TraitValue :
107+ def _get_trait (context : EvaluationContext , trait_key : str ) -> ContextValue :
108108 return (
109109 identity_context ["traits" ][trait_key ]
110110 if (identity_context := context ["identity" ])
@@ -115,7 +115,7 @@ def _get_trait(context: EvaluationContext, trait_key: str) -> TraitValue:
115115def get_context_value (
116116 context : EvaluationContext ,
117117 property : str ,
118- ) -> TraitValue :
118+ ) -> ContextValue :
119119 getter = CONTEXT_VALUE_GETTERS_BY_PROPERTY .get (property ) or partial (
120120 _get_trait ,
121121 trait_key = property ,
@@ -128,7 +128,7 @@ def get_context_value(
128128
129129def _matches_context_value (
130130 condition : SegmentConditionModel ,
131- context_value : TraitValue ,
131+ context_value : ContextValue ,
132132) -> bool :
133133 if matcher := MATCHERS_BY_OPERATOR .get (condition .operator ):
134134 return matcher (condition .value , context_value )
@@ -138,14 +138,14 @@ def _matches_context_value(
138138
139139def _evaluate_not_contains (
140140 segment_value : typing .Optional [str ],
141- context_value : TraitValue ,
141+ context_value : ContextValue ,
142142) -> bool :
143143 return isinstance (context_value , str ) and str (segment_value ) not in context_value
144144
145145
146146def _evaluate_regex (
147147 segment_value : typing .Optional [str ],
148- context_value : TraitValue ,
148+ context_value : ContextValue ,
149149) -> bool :
150150 return (
151151 context_value is not None
@@ -155,7 +155,7 @@ def _evaluate_regex(
155155
156156def _evaluate_modulo (
157157 segment_value : typing .Optional [str ],
158- context_value : TraitValue ,
158+ context_value : ContextValue ,
159159) -> bool :
160160 if not isinstance (context_value , (int , float )):
161161 return False
@@ -174,7 +174,7 @@ def _evaluate_modulo(
174174
175175
176176def _evaluate_in (
177- segment_value : typing .Optional [str ], context_value : TraitValue
177+ segment_value : typing .Optional [str ], context_value : ContextValue
178178) -> bool :
179179 if segment_value :
180180 if isinstance (context_value , str ):
@@ -188,11 +188,11 @@ def _evaluate_in(
188188
189189def _context_value_typed (
190190 func : typing .Callable [..., bool ],
191- ) -> typing .Callable [[typing .Optional [str ], TraitValue ], bool ]:
191+ ) -> typing .Callable [[typing .Optional [str ], ContextValue ], bool ]:
192192 @wraps (func )
193193 def inner (
194194 segment_value : typing .Optional [str ],
195- context_value : typing .Union [TraitValue , semver .Version ],
195+ context_value : typing .Union [ContextValue , semver .Version ],
196196 ) -> bool :
197197 with suppress (TypeError , ValueError ):
198198 if isinstance (context_value , str ) and is_semver (segment_value ):
@@ -207,7 +207,7 @@ def inner(
207207
208208
209209MATCHERS_BY_OPERATOR : typing .Dict [
210- ConditionOperator , typing .Callable [[typing .Optional [str ], TraitValue ], bool ]
210+ ConditionOperator , typing .Callable [[typing .Optional [str ], ContextValue ], bool ]
211211] = {
212212 constants .NOT_CONTAINS : _evaluate_not_contains ,
213213 constants .REGEX : _evaluate_regex ,
0 commit comments