Skip to content

Commit

Permalink
style: applied black formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Carrio <[email protected]>
  • Loading branch information
tcarrio committed Nov 8, 2022
1 parent 7ffc959 commit 6d86aa1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
13 changes: 7 additions & 6 deletions open_feature/immutable_dict/mapping_proxy_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ class MappingProxyType(dict):
to:
`from types import MappingProxyType`
"""

def __hash__(self):
return id(self)

def _immutable(self, *args, **kws):
raise TypeError('immutable instance of dictionary')
raise TypeError("immutable instance of dictionary")

__setitem__ = _immutable
__delitem__ = _immutable
clear = _immutable
update = _immutable
setdefault = _immutable
pop = _immutable
popitem = _immutable
clear = _immutable
update = _immutable
setdefault = _immutable
pop = _immutable
popitem = _immutable
28 changes: 19 additions & 9 deletions open_feature/open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def evaluate_flag_details(
if evaluation_context is None:
evaluation_context = EvaluationContext()

evaluation_hooks, hook_hints = self.__extract_evaluation_options(flag_evaluation_options)
evaluation_hooks, hook_hints = self.__extract_evaluation_options(
flag_evaluation_options
)

hook_context = HookContext(
flag_key=flag_key,
Expand Down Expand Up @@ -284,15 +286,23 @@ def _create_provider_evaluation(

return get_details_callable(*args)

def __extract_evaluation_options(self, flag_evaluation_options: typing.Any) -> typing.Tuple(typing.List[Hook], MappingProxyType):
def __extract_evaluation_options(
self, flag_evaluation_options: typing.Any
) -> typing.Tuple(typing.List[Hook], MappingProxyType):
evaluation_hooks: typing.List[Hook] = []
hook_hints: dict = {}

if flag_evaluation_options is dict:
if 'hook_hints' in flag_evaluation_options and flag_evaluation_options['hook_hints'] is dict:
hook_hints = dict(flag_evaluation_options['hook_hints'])

if 'hooks' in flag_evaluation_options and flag_evaluation_options['hooks'] is list:
evaluation_hooks = flag_evaluation_options['hooks']

return (evaluation_hooks, MappingProxyType(hook_hints))
if (
"hook_hints" in flag_evaluation_options
and flag_evaluation_options["hook_hints"] is dict
):
hook_hints = dict(flag_evaluation_options["hook_hints"])

if (
"hooks" in flag_evaluation_options
and flag_evaluation_options["hooks"] is list
):
evaluation_hooks = flag_evaluation_options["hooks"]

return (evaluation_hooks, MappingProxyType(hook_hints))
4 changes: 3 additions & 1 deletion tests/hooks/test_hook_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def test_after_hooks_run_after_method(mock_hook):
# Then
mock_hook.supports_flag_value_type.assert_called_once()
mock_hook.after.assert_called_once()
mock_hook.error.assert_called_with(hook_context, flag_evaluation_details, hook_hints)
mock_hook.error.assert_called_with(
hook_context, flag_evaluation_details, hook_hints
)


def test_finally_after_hooks_run_finally_after_method(mock_hook):
Expand Down

0 comments on commit 6d86aa1

Please sign in to comment.