-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement transaction context (#389)
* feat: implement transaction context Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> * fix: lint issues Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> * feat: add tests for context merging Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> * feat: fix pre-commit checks Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> * feat: use elipsis instead of pass Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> * Update openfeature/transaction_context/no_op_transaction_context_propagator.py Co-authored-by: Anton Grübel <anton.gruebel@gmail.com> Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> * feat: pr feedback Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> --------- Signed-off-by: Lukas Reining <lukas.reining@codecentric.de> Co-authored-by: Anton Grübel <anton.gruebel@gmail.com>
- Loading branch information
1 parent
f024a6f
commit 9b97130
Showing
10 changed files
with
396 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,11 @@ | ||
from openfeature.transaction_context.context_var_transaction_context_propagator import ( | ||
ContextVarsTransactionContextPropagator, | ||
) | ||
from openfeature.transaction_context.transaction_context_propagator import ( | ||
TransactionContextPropagator, | ||
) | ||
|
||
__all__ = [ | ||
"TransactionContextPropagator", | ||
"ContextVarsTransactionContextPropagator", | ||
] |
18 changes: 18 additions & 0 deletions
18
openfeature/transaction_context/context_var_transaction_context_propagator.py
This file contains 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,18 @@ | ||
from contextvars import ContextVar | ||
|
||
from openfeature.evaluation_context import EvaluationContext | ||
from openfeature.transaction_context.transaction_context_propagator import ( | ||
TransactionContextPropagator, | ||
) | ||
|
||
|
||
class ContextVarsTransactionContextPropagator(TransactionContextPropagator): | ||
_transaction_context_var: ContextVar[EvaluationContext] = ContextVar( | ||
"transaction_context", default=EvaluationContext() | ||
) | ||
|
||
def get_transaction_context(self) -> EvaluationContext: | ||
return self._transaction_context_var.get() | ||
|
||
def set_transaction_context(self, transaction_context: EvaluationContext) -> None: | ||
self._transaction_context_var.set(transaction_context) |
12 changes: 12 additions & 0 deletions
12
openfeature/transaction_context/no_op_transaction_context_propagator.py
This file contains 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,12 @@ | ||
from openfeature.evaluation_context import EvaluationContext | ||
from openfeature.transaction_context.transaction_context_propagator import ( | ||
TransactionContextPropagator, | ||
) | ||
|
||
|
||
class NoOpTransactionContextPropagator(TransactionContextPropagator): | ||
def get_transaction_context(self) -> EvaluationContext: | ||
return EvaluationContext() | ||
|
||
def set_transaction_context(self, transaction_context: EvaluationContext) -> None: | ||
pass |
11 changes: 11 additions & 0 deletions
11
openfeature/transaction_context/transaction_context_propagator.py
This file contains 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,11 @@ | ||
import typing | ||
|
||
from openfeature.evaluation_context import EvaluationContext | ||
|
||
|
||
class TransactionContextPropagator(typing.Protocol): | ||
def get_transaction_context(self) -> EvaluationContext: ... | ||
|
||
def set_transaction_context( | ||
self, transaction_context: EvaluationContext | ||
) -> None: ... |
This file contains 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 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
Oops, something went wrong.