2020)
2121from flag_engine .result .types import EvaluationResult , FlagResult , SegmentResult
2222from flag_engine .segments import constants
23- from flag_engine .segments .types import ConditionOperator , ContextValue , is_context_value
23+ from flag_engine .segments .types import (
24+ ConditionOperator ,
25+ ContextValue ,
26+ MetadataT ,
27+ is_context_value ,
28+ )
2429from flag_engine .segments .utils import escape_double_quotes , get_matching_function
2530from flag_engine .utils .hashing import get_hashed_percentage_for_object_ids
2631from flag_engine .utils .semver import is_semver
@@ -32,14 +37,16 @@ class FeatureContextWithSegmentName(typing.TypedDict):
3237 segment_name : str
3338
3439
35- def get_evaluation_result (context : EvaluationContext ) -> EvaluationResult :
40+ def get_evaluation_result (
41+ context : EvaluationContext [MetadataT ],
42+ ) -> EvaluationResult [MetadataT ]:
3643 """
3744 Get the evaluation result for a given context.
3845
3946 :param context: the evaluation context
4047 :return: EvaluationResult containing the context, flags, and segments
4148 """
42- segments : list [SegmentResult ] = []
49+ segments : list [SegmentResult [ MetadataT ] ] = []
4350 flags : dict [str , FlagResult ] = {}
4451
4552 segment_feature_contexts : dict [SupportsStr , FeatureContextWithSegmentName ] = {}
@@ -48,7 +55,7 @@ def get_evaluation_result(context: EvaluationContext) -> EvaluationResult:
4855 if not is_context_in_segment (context , segment_context ):
4956 continue
5057
51- segment_result : SegmentResult = {
58+ segment_result : SegmentResult [ MetadataT ] = {
5259 "key" : segment_context ["key" ],
5360 "name" : segment_context ["name" ],
5461 }
@@ -152,8 +159,8 @@ def get_flag_result_from_feature_context(
152159
153160
154161def is_context_in_segment (
155- context : EvaluationContext ,
156- segment_context : SegmentContext ,
162+ context : EvaluationContext [ MetadataT ] ,
163+ segment_context : SegmentContext [ MetadataT ] ,
157164) -> bool :
158165 return bool (rules := segment_context ["rules" ]) and all (
159166 context_matches_rule (
@@ -164,7 +171,7 @@ def is_context_in_segment(
164171
165172
166173def context_matches_rule (
167- context : EvaluationContext ,
174+ context : EvaluationContext [ MetadataT ] ,
168175 rule : SegmentRule ,
169176 segment_key : SupportsStr ,
170177) -> bool :
@@ -194,7 +201,7 @@ def context_matches_rule(
194201
195202
196203def context_matches_condition (
197- context : EvaluationContext ,
204+ context : EvaluationContext [ MetadataT ] ,
198205 condition : SegmentCondition ,
199206 segment_key : SupportsStr ,
200207) -> bool :
@@ -255,7 +262,7 @@ def context_matches_condition(
255262
256263
257264def get_context_value (
258- context : EvaluationContext ,
265+ context : EvaluationContext [ MetadataT ] ,
259266 property : str ,
260267) -> ContextValue :
261268 value = None
@@ -353,7 +360,7 @@ def inner(
353360@lru_cache
354361def _get_context_value_getter (
355362 property : str ,
356- ) -> typing .Callable [[EvaluationContext ], ContextValue ]:
363+ ) -> typing .Callable [[EvaluationContext [ MetadataT ] ], ContextValue ]:
357364 """
358365 Get a function to retrieve a context value based on property value,
359366 assumed to be either a JSONPath string or a trait key.
@@ -370,7 +377,7 @@ def _get_context_value_getter(
370377 f'$.identity.traits["{ escape_double_quotes (property )} "]' ,
371378 )
372379
373- def getter (context : EvaluationContext ) -> ContextValue :
380+ def getter (context : EvaluationContext [ MetadataT ] ) -> ContextValue :
374381 if typing .TYPE_CHECKING : # pragma: no cover
375382 # Ugly hack to satisfy mypy :(
376383 data = dict (context )
0 commit comments