Skip to content

Commit 4e16c60

Browse files
committed
docs: address review feedback on type checks
Signed-off-by: Hexecu <vaingloryhex@gmail.com>
1 parent 1e2e89d commit 4e16c60

2 files changed

Lines changed: 1 addition & 32 deletions

File tree

‎openfeature/client.py‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -861,19 +861,6 @@ async def _create_provider_evaluation_async(
861861
default_value: FlagValueType,
862862
evaluation_context: EvaluationContext | None = None,
863863
) -> FlagEvaluationDetails[FlagValueType]:
864-
"""
865-
Resolve a flag asynchronously and validate the returned value.
866-
867-
Provider-reported errors are returned unchanged. A type mismatch detected
868-
by the client returns the caller's default with TYPE_MISMATCH error details.
869-
870-
:param provider: the provider selected for this evaluation
871-
:param flag_type: the requested flag type
872-
:param flag_key: the key of the selected flag
873-
:param default_value: fallback used for an unknown type or a type mismatch
874-
:param evaluation_context: context passed to the provider
875-
:return: evaluation details containing the resolved value or fallback
876-
"""
877864
get_details_callables_async: Mapping[FlagType, ResolveDetailsCallableAsync] = {
878865
FlagType.BOOLEAN: provider.resolve_boolean_details_async,
879866
FlagType.INTEGER: provider.resolve_integer_details_async,
@@ -1004,17 +991,6 @@ def track(
1004991
def _typecheck_flag_value(
1005992
value: typing.Any, flag_type: FlagType
1006993
) -> OpenFeatureError | None:
1007-
"""
1008-
Check a resolved value against the requested flag type without coercing it.
1009-
1010-
Booleans are not integer flag values, even though bool subclasses int in
1011-
Python. Other subclasses of the expected type remain valid.
1012-
1013-
:param value: the value returned by the provider
1014-
:param flag_type: the requested flag type
1015-
:return: None for a matching value, TypeMismatchError for an incompatible
1016-
value, or GeneralError for an unknown flag type
1017-
"""
1018994
type_map: TypeMap = {
1019995
FlagType.BOOLEAN: bool,
1020996
FlagType.STRING: str,
@@ -1025,6 +1001,7 @@ def _typecheck_flag_value(
10251001
py_type = type_map.get(flag_type)
10261002
if not py_type:
10271003
return GeneralError(error_message="Unknown flag type")
1004+
# bool subclasses int, but booleans are not integer flag values.
10281005
if not isinstance(value, py_type) or (
10291006
flag_type == FlagType.INTEGER and isinstance(value, bool)
10301007
):

‎tests/test_client.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ async def test_client_type_mismatch_exceptions():
424424

425425
@pytest.mark.asyncio
426426
async def test_typecheck_flag_value_general_error():
427-
"""Unknown flag types produce GENERAL rather than TYPE_MISMATCH."""
428427
# Given
429428
flag_value = "A"
430429
flag_type = None
@@ -454,7 +453,6 @@ async def test_typecheck_flag_value_general_error():
454453
async def test_client_returns_default_on_type_mismatch(
455454
flag_type, flag_value, default_value, is_async
456455
):
457-
"""Both APIs return typed defaults and pass the fallback to finally hooks."""
458456
provider = InMemoryProvider(
459457
{"flag": InMemoryFlag("enabled", {"enabled": flag_value})}
460458
)
@@ -520,7 +518,6 @@ async def test_client_returns_default_on_type_mismatch(
520518
async def test_client_preserves_matching_flag_types(
521519
flag_type, flag_value, default_value, is_async
522520
):
523-
"""Matching values keep their type and successful evaluation details."""
524521
provider = InMemoryProvider(
525522
{"flag": InMemoryFlag("enabled", {"enabled": flag_value})}
526523
)
@@ -548,19 +545,14 @@ async def test_client_preserves_matching_flag_types(
548545

549546

550547
def test_typecheck_flag_value_accepts_integer_subclasses():
551-
"""Rejecting booleans must not reject other integer subclasses."""
552-
553548
class IntegerValue(int):
554-
"""An integer subtype with the same value semantics as int."""
555-
556549
pass
557550

558551
assert _typecheck_flag_value(IntegerValue(1), FlagType.INTEGER) is None
559552

560553

561554
@pytest.mark.asyncio
562555
async def test_typecheck_flag_value_type_mismatch_error():
563-
"""An incompatible value reports both the expected and actual types."""
564556
# Given
565557
flag_value = "A"
566558
flag_type = FlagType.BOOLEAN

0 commit comments

Comments
 (0)