Skip to content

chore: use keyword arguments, validate test #446

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions openfeature/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,6 @@ async def _create_provider_evaluation_async(
default_value: typing.Any,
evaluation_context: typing.Optional[EvaluationContext] = None,
) -> FlagEvaluationDetails[typing.Any]:
args = (
flag_key,
default_value,
evaluation_context,
)
get_details_callables_async: typing.Mapping[
FlagType, GetDetailCallableAsync
] = {
Expand All @@ -719,7 +714,11 @@ async def _create_provider_evaluation_async(
if not get_details_callable:
raise GeneralError(error_message="Unknown flag type")

resolution = await get_details_callable(*args)
resolution = await get_details_callable( # type: ignore[call-arg]
flag_key=flag_key,
default_value=default_value,
evaluation_context=evaluation_context,
)
resolution.raise_for_error()

# we need to check the get_args to be compatible with union types.
Expand Down Expand Up @@ -753,12 +752,6 @@ def _create_provider_evaluation(
:return: a FlagEvaluationDetails object with the fully evaluated flag from a
provider
"""
args = (
flag_key,
default_value,
evaluation_context,
)

get_details_callables: typing.Mapping[FlagType, GetDetailCallable] = {
FlagType.BOOLEAN: provider.resolve_boolean_details,
FlagType.INTEGER: provider.resolve_integer_details,
Expand All @@ -771,7 +764,11 @@ def _create_provider_evaluation(
if not get_details_callable:
raise GeneralError(error_message="Unknown flag type")

resolution = get_details_callable(*args)
resolution = get_details_callable( # type: ignore[call-arg]
flag_key=flag_key,
default_value=default_value,
evaluation_context=evaluation_context,
)
resolution.raise_for_error()

# we need to check the get_args to be compatible with union types.
Expand Down
12 changes: 10 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,20 @@ def test_client_should_merge_contexts():
invocation_context = EvaluationContext(
targeting_key="invocation", attributes={"invocation_attr": "invocation_value"}
)
client.get_boolean_details("flag", False, invocation_context)
flag_input = "flag"
flag_default = False
client.get_boolean_details(flag_input, flag_default, invocation_context)

# Retrieve the call arguments
args, kwargs = provider.resolve_boolean_details.call_args
flag_key, default_value, context = args
flag_key, default_value, context = (
kwargs["flag_key"],
kwargs["default_value"],
kwargs["evaluation_context"],
)

assert flag_key == flag_input
assert default_value is flag_default
assert context.targeting_key == "invocation" # Last one in the merge chain
assert context.attributes["global_attr"] == "global_value"
assert context.attributes["transaction_attr"] == "transaction_value"
Expand Down
Loading