Skip to content

Commit 9fe8a5f

Browse files
committed
feature/spec-0.2.0: Check flag type after provider response
Signed-off-by: Andrew Helsby <[email protected]> Signed-off-by: Andrew Helsby <[email protected]>
1 parent c037b31 commit 9fe8a5f

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

open_feature/flag_evaluation/flag_type.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
class FlagType(Enum):
5-
BOOLEAN = 1
6-
STRING = 2
7-
OBJECT = 3
8-
FLOAT = 4
9-
INTEGER = 5
5+
BOOLEAN = bool
6+
STRING = str
7+
OBJECT = dict
8+
FLOAT = float
9+
INTEGER = int

open_feature/open_feature_client.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,11 @@ def _create_provider_evaluation(
336336

337337
value = get_details_callable(*args)
338338

339-
if flag_type in NUMERIC_TYPES:
340-
value.value = self._convert_numeric_types(flag_type, value.value)
339+
self._check_flag_type(flag_type, value.value)
341340

342341
return value
343342

344343
@staticmethod
345-
def _convert_numeric_types(flag_type: FlagType, current_value):
346-
converter = {
347-
FlagType.FLOAT: float,
348-
FlagType.INTEGER: int,
349-
}.get(flag_type)
350-
351-
try:
352-
return converter(current_value)
353-
except ValueError:
344+
def _check_flag_type(flag_type: FlagType, current_value):
345+
if not isinstance(current_value, flag_type.value):
354346
raise TypeMismatchError()

0 commit comments

Comments
 (0)