feat: add client-level evaluation context setter#586
feat: add client-level evaluation context setter#586buildingisfun23 wants to merge 1 commit intoopen-feature:mainfrom
Conversation
…atureClient Allow setting evaluation context at the client level, following the OpenFeature spec for context merging: API-level context is merged with client-level context, then with invocation-level context, where later levels take precedence over earlier ones. Closes open-feature#500
There was a problem hiding this comment.
Code Review
This pull request introduces client-level evaluation context management by adding set_evaluation_context and get_evaluation_context methods to the OpenFeatureClient class. It also includes comprehensive tests to verify context merging behavior across API, client, and invocation levels for both synchronous and asynchronous calls. The feedback suggests updating the context setter to handle potential None values by defaulting to an empty EvaluationContext, ensuring type consistency.
| def set_evaluation_context(self, context: EvaluationContext) -> None: | ||
| self.context = context |
There was a problem hiding this comment.
To maintain consistency with the class constructor and ensure that self.context always holds a valid EvaluationContext instance (as expected by the type hint in get_evaluation_context), the setter should handle None by defaulting to an empty context. This prevents potential type errors if None is passed at runtime.
| def set_evaluation_context(self, context: EvaluationContext) -> None: | |
| self.context = context | |
| def set_evaluation_context(self, context: EvaluationContext) -> None: | |
| self.context = context or EvaluationContext() |
|
please check this comment #565 (comment) for a previous PR targeting the same issue |
Summary
set_evaluation_context()andget_evaluation_context()methods toOpenFeatureClientFixes #500