-
Notifications
You must be signed in to change notification settings - Fork 38
fix: fix cycle dependency between api and client #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4d0bd2
fix cycle dependency between api and client
gruebel f5239e1
Merge branch 'main' into fix-imports
beeme1mr be669bd
remove comment
gruebel f087c40
Merge remote-tracking branch 'origin/main' into fix-imports
gruebel 2148972
Merge remote-tracking branch 'origin/fix-imports' into fix-imports
gruebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import typing | ||
| from dataclasses import dataclass, field | ||
|
|
||
| from openfeature.exception import GeneralError | ||
|
|
||
| __all__ = ["EvaluationContext", "get_evaluation_context", "set_evaluation_context"] | ||
|
|
||
|
|
||
| @dataclass | ||
| class EvaluationContext: | ||
| targeting_key: typing.Optional[str] = None | ||
| attributes: dict = field(default_factory=dict) | ||
|
|
||
| def merge(self, ctx2: EvaluationContext) -> EvaluationContext: | ||
| if not (self and ctx2): | ||
| return self or ctx2 | ||
|
|
||
| attributes = {**self.attributes, **ctx2.attributes} | ||
| targeting_key = ctx2.targeting_key or self.targeting_key | ||
|
|
||
| return EvaluationContext(targeting_key=targeting_key, attributes=attributes) | ||
|
|
||
|
|
||
| def get_evaluation_context() -> EvaluationContext: | ||
| return _evaluation_context | ||
|
|
||
|
|
||
| def set_evaluation_context(evaluation_context: EvaluationContext) -> None: | ||
| global _evaluation_context | ||
| if evaluation_context is None: | ||
| raise GeneralError(error_message="No api level evaluation context") | ||
| _evaluation_context = evaluation_context | ||
|
|
||
|
|
||
| # need to be at the bottom, because of the definition order | ||
| _evaluation_context = EvaluationContext() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,40 @@ | ||
| from openfeature.evaluation_context import EvaluationContext | ||
| from openfeature.transaction_context.context_var_transaction_context_propagator import ( | ||
| ContextVarsTransactionContextPropagator, | ||
| ) | ||
| from openfeature.transaction_context.no_op_transaction_context_propagator import ( | ||
| NoOpTransactionContextPropagator, | ||
| ) | ||
| from openfeature.transaction_context.transaction_context_propagator import ( | ||
| TransactionContextPropagator, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ContextVarsTransactionContextPropagator", | ||
| "TransactionContextPropagator", | ||
| "get_transaction_context", | ||
| "set_transaction_context", | ||
| "set_transaction_context_propagator", | ||
| ] | ||
|
|
||
| _evaluation_transaction_context_propagator: TransactionContextPropagator = ( | ||
| NoOpTransactionContextPropagator() | ||
| ) | ||
|
|
||
|
|
||
| def set_transaction_context_propagator( | ||
| transaction_context_propagator: TransactionContextPropagator, | ||
| ) -> None: | ||
| global _evaluation_transaction_context_propagator | ||
| _evaluation_transaction_context_propagator = transaction_context_propagator | ||
|
|
||
|
|
||
| def get_transaction_context() -> EvaluationContext: | ||
| return _evaluation_transaction_context_propagator.get_transaction_context() | ||
|
|
||
|
|
||
| def set_transaction_context(evaluation_context: EvaluationContext) -> None: | ||
| global _evaluation_transaction_context_propagator | ||
| _evaluation_transaction_context_propagator.set_transaction_context( | ||
| evaluation_context | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.