Skip to content

Commit f29c450

Browse files
authored
chore: use keyword arguments, validate test (#446)
Signed-off-by: leohoare <leo@insight.co>
1 parent f907855 commit f29c450

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

openfeature/client.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,6 @@ async def _create_provider_evaluation_async(
701701
default_value: typing.Any,
702702
evaluation_context: typing.Optional[EvaluationContext] = None,
703703
) -> FlagEvaluationDetails[typing.Any]:
704-
args = (
705-
flag_key,
706-
default_value,
707-
evaluation_context,
708-
)
709704
get_details_callables_async: typing.Mapping[
710705
FlagType, GetDetailCallableAsync
711706
] = {
@@ -719,7 +714,11 @@ async def _create_provider_evaluation_async(
719714
if not get_details_callable:
720715
raise GeneralError(error_message="Unknown flag type")
721716

722-
resolution = await get_details_callable(*args)
717+
resolution = await get_details_callable( # type: ignore[call-arg]
718+
flag_key=flag_key,
719+
default_value=default_value,
720+
evaluation_context=evaluation_context,
721+
)
723722
resolution.raise_for_error()
724723

725724
# we need to check the get_args to be compatible with union types.
@@ -753,12 +752,6 @@ def _create_provider_evaluation(
753752
:return: a FlagEvaluationDetails object with the fully evaluated flag from a
754753
provider
755754
"""
756-
args = (
757-
flag_key,
758-
default_value,
759-
evaluation_context,
760-
)
761-
762755
get_details_callables: typing.Mapping[FlagType, GetDetailCallable] = {
763756
FlagType.BOOLEAN: provider.resolve_boolean_details,
764757
FlagType.INTEGER: provider.resolve_integer_details,
@@ -771,7 +764,11 @@ def _create_provider_evaluation(
771764
if not get_details_callable:
772765
raise GeneralError(error_message="Unknown flag type")
773766

774-
resolution = get_details_callable(*args)
767+
resolution = get_details_callable( # type: ignore[call-arg]
768+
flag_key=flag_key,
769+
default_value=default_value,
770+
evaluation_context=evaluation_context,
771+
)
775772
resolution.raise_for_error()
776773

777774
# we need to check the get_args to be compatible with union types.

tests/test_client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,20 @@ def test_client_should_merge_contexts():
526526
invocation_context = EvaluationContext(
527527
targeting_key="invocation", attributes={"invocation_attr": "invocation_value"}
528528
)
529-
client.get_boolean_details("flag", False, invocation_context)
529+
flag_input = "flag"
530+
flag_default = False
531+
client.get_boolean_details(flag_input, flag_default, invocation_context)
530532

531533
# Retrieve the call arguments
532534
args, kwargs = provider.resolve_boolean_details.call_args
533-
flag_key, default_value, context = args
535+
flag_key, default_value, context = (
536+
kwargs["flag_key"],
537+
kwargs["default_value"],
538+
kwargs["evaluation_context"],
539+
)
534540

541+
assert flag_key == flag_input
542+
assert default_value is flag_default
535543
assert context.targeting_key == "invocation" # Last one in the merge chain
536544
assert context.attributes["global_attr"] == "global_value"
537545
assert context.attributes["transaction_attr"] == "transaction_value"

0 commit comments

Comments
 (0)