1212 EvaluationContext ,
1313 FeatureContext ,
1414 SegmentCondition ,
15- SegmentContext ,
16- SegmentRule ,
1715)
16+ from flag_engine .context .types import SegmentCondition1 as SegmentConditionWithStrValue
17+ from flag_engine .context .types import SegmentContext , SegmentRule
1818from flag_engine .environments .models import EnvironmentModel
1919from flag_engine .identities .models import IdentityModel
2020from flag_engine .identities .traits .types import ContextValue
@@ -227,6 +227,22 @@ def context_matches_condition(
227227 else None
228228 )
229229
230+ if condition ["operator" ] == constants .IN :
231+ in_values = (
232+ condition_value
233+ if isinstance (condition_value := condition ["value" ], list )
234+ else condition_value .split ("," )
235+ )
236+ if isinstance (context_value , int ) and not any (
237+ context_value is x for x in (False , True )
238+ ):
239+ return str (context_value ) in in_values
240+ return context_value in in_values
241+
242+ # mypy is too inflexible here, we know that, at this point,
243+ # the condition value is not a list[str]
244+ condition = typing .cast (SegmentConditionWithStrValue , condition )
245+
230246 if condition ["operator" ] == constants .PERCENTAGE_SPLIT :
231247 if context_value is not None :
232248 object_ids = [segment_key , context_value ]
@@ -272,7 +288,7 @@ def get_context_value(
272288
273289
274290def _matches_context_value (
275- condition : SegmentCondition ,
291+ condition : SegmentConditionWithStrValue ,
276292 context_value : ContextValue ,
277293) -> bool :
278294 if matcher := MATCHERS_BY_OPERATOR .get (condition ["operator" ]):
@@ -318,19 +334,6 @@ def _evaluate_modulo(
318334 return context_value % divisor == remainder
319335
320336
321- def _evaluate_in (
322- segment_value : typing .Optional [str ], context_value : ContextValue
323- ) -> bool :
324- if segment_value :
325- if isinstance (context_value , str ):
326- return context_value in segment_value .split ("," )
327- if isinstance (context_value , int ) and not any (
328- context_value is x for x in (False , True )
329- ):
330- return str (context_value ) in segment_value .split ("," )
331- return False
332-
333-
334337def _context_value_typed (
335338 func : typing .Callable [..., bool ],
336339) -> typing .Callable [[typing .Optional [str ], ContextValue ], bool ]:
@@ -357,7 +360,6 @@ def inner(
357360 constants .NOT_CONTAINS : _evaluate_not_contains ,
358361 constants .REGEX : _evaluate_regex ,
359362 constants .MODULO : _evaluate_modulo ,
360- constants .IN : _evaluate_in ,
361363 constants .EQUAL : _context_value_typed (operator .eq ),
362364 constants .GREATER_THAN : _context_value_typed (operator .gt ),
363365 constants .GREATER_THAN_INCLUSIVE : _context_value_typed (operator .ge ),
0 commit comments