Skip to content

Commit

Permalink
feature/spec-0.2.0: Check flag type after provider response
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>
  • Loading branch information
ajhelsby committed Nov 3, 2022
1 parent c037b31 commit 9fe8a5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
10 changes: 5 additions & 5 deletions open_feature/flag_evaluation/flag_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class FlagType(Enum):
BOOLEAN = 1
STRING = 2
OBJECT = 3
FLOAT = 4
INTEGER = 5
BOOLEAN = bool
STRING = str
OBJECT = dict
FLOAT = float
INTEGER = int
14 changes: 3 additions & 11 deletions open_feature/open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,11 @@ def _create_provider_evaluation(

value = get_details_callable(*args)

if flag_type in NUMERIC_TYPES:
value.value = self._convert_numeric_types(flag_type, value.value)
self._check_flag_type(flag_type, value.value)

return value

@staticmethod
def _convert_numeric_types(flag_type: FlagType, current_value):
converter = {
FlagType.FLOAT: float,
FlagType.INTEGER: int,
}.get(flag_type)

try:
return converter(current_value)
except ValueError:
def _check_flag_type(flag_type: FlagType, current_value):
if not isinstance(current_value, flag_type.value):
raise TypeMismatchError()

0 comments on commit 9fe8a5f

Please sign in to comment.