fix: Fix type checking (#25)
* Fix type checking within client Signed-off-by: Manuel Schönlaub <manuel.schoenlaub@gmail.com> * Make linter happy Signed-off-by: Manuel Schönlaub <manuel.schoenlaub@gmail.com> * Migrate Hook Hints to Mapping Signed-off-by: Manuel Schönlaub <manuel.schoenlaub@gmail.com> * Fix type annotations in FlagEvaluationDetails Signed-off-by: Manuel Schönlaub <manuel.schoenlaub@gmail.com> * Fix last hint typing Signed-off-by: Manuel Schönlaub <manuel.schonlaub@prodigygame.com> * Rework typing Signed-off-by: Manuel Schönlaub <manuel.schonlaub@prodigygame.com> Signed-off-by: Manuel Schönlaub <manuel.schoenlaub@gmail.com> Signed-off-by: Manuel Schönlaub <manuel.schonlaub@prodigygame.com>
This commit is contained in:
parent
f60b44e014
commit
50f5a484a0
|
|
@ -1,5 +1,12 @@
|
||||||
|
import typing
|
||||||
|
|
||||||
|
|
||||||
class EvaluationContext:
|
class EvaluationContext:
|
||||||
def __init__(self, targeting_key: str = None, attributes: dict = None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
targeting_key: typing.Optional[str] = None,
|
||||||
|
attributes: typing.Optional[dict] = None,
|
||||||
|
):
|
||||||
self.targeting_key = targeting_key
|
self.targeting_key = targeting_key
|
||||||
self.attributes = attributes or {}
|
self.attributes = attributes or {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class OpenFeatureError(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, error_message: typing.Optional[str] = None, error_code: ErrorCode = None
|
self, error_code: ErrorCode, error_message: typing.Optional[str] = None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Constructor for the generic OpenFeatureError.
|
Constructor for the generic OpenFeatureError.
|
||||||
|
|
@ -35,7 +35,7 @@ class FlagNotFoundError(OpenFeatureError):
|
||||||
@param error_message: an optional string message representing
|
@param error_message: an optional string message representing
|
||||||
why the error has been raised
|
why the error has been raised
|
||||||
"""
|
"""
|
||||||
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)
|
super().__init__(ErrorCode.FLAG_NOT_FOUND, error_message)
|
||||||
|
|
||||||
|
|
||||||
class GeneralError(OpenFeatureError):
|
class GeneralError(OpenFeatureError):
|
||||||
|
|
@ -51,7 +51,7 @@ class GeneralError(OpenFeatureError):
|
||||||
@param error_message: an optional string message representing why the error
|
@param error_message: an optional string message representing why the error
|
||||||
has been raised
|
has been raised
|
||||||
"""
|
"""
|
||||||
super().__init__(error_message, ErrorCode.GENERAL)
|
super().__init__(ErrorCode.GENERAL, error_message)
|
||||||
|
|
||||||
|
|
||||||
class ParseError(OpenFeatureError):
|
class ParseError(OpenFeatureError):
|
||||||
|
|
@ -67,7 +67,7 @@ class ParseError(OpenFeatureError):
|
||||||
@param error_message: an optional string message representing why the
|
@param error_message: an optional string message representing why the
|
||||||
error has been raised
|
error has been raised
|
||||||
"""
|
"""
|
||||||
super().__init__(error_message, ErrorCode.PARSE_ERROR)
|
super().__init__(ErrorCode.PARSE_ERROR, error_message)
|
||||||
|
|
||||||
|
|
||||||
class TypeMismatchError(OpenFeatureError):
|
class TypeMismatchError(OpenFeatureError):
|
||||||
|
|
@ -83,7 +83,7 @@ class TypeMismatchError(OpenFeatureError):
|
||||||
@param error_message: an optional string message representing why the
|
@param error_message: an optional string message representing why the
|
||||||
error has been raised
|
error has been raised
|
||||||
"""
|
"""
|
||||||
super().__init__(error_message, ErrorCode.TYPE_MISMATCH)
|
super().__init__(ErrorCode.TYPE_MISMATCH, error_message)
|
||||||
|
|
||||||
|
|
||||||
class TargetingKeyMissingError(OpenFeatureError):
|
class TargetingKeyMissingError(OpenFeatureError):
|
||||||
|
|
@ -92,14 +92,14 @@ class TargetingKeyMissingError(OpenFeatureError):
|
||||||
but one was not provided in the evaluation context.
|
but one was not provided in the evaluation context.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, error_message: str = None):
|
def __init__(self, error_message: typing.Optional[str] = None):
|
||||||
"""
|
"""
|
||||||
Constructor for the TargetingKeyMissingError. The error code for this type of
|
Constructor for the TargetingKeyMissingError. The error code for this type of
|
||||||
exception is ErrorCode.TARGETING_KEY_MISSING.
|
exception is ErrorCode.TARGETING_KEY_MISSING.
|
||||||
@param error_message: a string message representing why the error has been
|
@param error_message: a string message representing why the error has been
|
||||||
raised
|
raised
|
||||||
"""
|
"""
|
||||||
super().__init__(error_message, ErrorCode.TARGETING_KEY_MISSING)
|
super().__init__(ErrorCode.TARGETING_KEY_MISSING, error_message)
|
||||||
|
|
||||||
|
|
||||||
class InvalidContextError(OpenFeatureError):
|
class InvalidContextError(OpenFeatureError):
|
||||||
|
|
@ -108,11 +108,11 @@ class InvalidContextError(OpenFeatureError):
|
||||||
requirements.
|
requirements.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, error_message: str = None):
|
def __init__(self, error_message: typing.Optional[str]):
|
||||||
"""
|
"""
|
||||||
Constructor for the InvalidContextError. The error code for this type of
|
Constructor for the InvalidContextError. The error code for this type of
|
||||||
exception is ErrorCode.INVALID_CONTEXT.
|
exception is ErrorCode.INVALID_CONTEXT.
|
||||||
@param error_message: a string message representing why the error has been
|
@param error_message: a string message representing why the error has been
|
||||||
raised
|
raised
|
||||||
"""
|
"""
|
||||||
super().__init__(error_message, ErrorCode.INVALID_CONTEXT)
|
super().__init__(ErrorCode.INVALID_CONTEXT, error_message)
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@ from dataclasses import dataclass
|
||||||
from open_feature.exception.error_code import ErrorCode
|
from open_feature.exception.error_code import ErrorCode
|
||||||
from open_feature.flag_evaluation.reason import Reason
|
from open_feature.flag_evaluation.reason import Reason
|
||||||
|
|
||||||
|
T = typing.TypeVar("T", covariant=True)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FlagEvaluationDetails:
|
class FlagEvaluationDetails(typing.Generic[T]):
|
||||||
flag_key: str
|
flag_key: str
|
||||||
value: typing.Any
|
value: T
|
||||||
variant: str = None
|
variant: typing.Optional[str] = None
|
||||||
reason: Reason = None
|
reason: typing.Optional[Reason] = None
|
||||||
error_code: ErrorCode = None
|
error_code: typing.Optional[ErrorCode] = None
|
||||||
error_message: typing.Optional[str] = None
|
error_message: typing.Optional[str] = None
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ class HookContext:
|
||||||
flag_type: FlagType
|
flag_type: FlagType
|
||||||
default_value: typing.Any
|
default_value: typing.Any
|
||||||
evaluation_context: EvaluationContext
|
evaluation_context: EvaluationContext
|
||||||
client_metadata: dict = None
|
client_metadata: typing.Optional[dict] = None
|
||||||
provider_metadata: dict = None
|
provider_metadata: typing.Optional[dict] = None
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ def error_hooks(
|
||||||
hook_context: HookContext,
|
hook_context: HookContext,
|
||||||
exception: Exception,
|
exception: Exception,
|
||||||
hooks: typing.List[Hook],
|
hooks: typing.List[Hook],
|
||||||
hints: dict,
|
hints: typing.Optional[typing.Mapping] = None,
|
||||||
):
|
):
|
||||||
kwargs = {"hook_context": hook_context, "exception": exception, "hints": hints}
|
kwargs = {"hook_context": hook_context, "exception": exception, "hints": hints}
|
||||||
_execute_hooks(
|
_execute_hooks(
|
||||||
|
|
@ -27,7 +27,7 @@ def after_all_hooks(
|
||||||
flag_type: FlagType,
|
flag_type: FlagType,
|
||||||
hook_context: HookContext,
|
hook_context: HookContext,
|
||||||
hooks: typing.List[Hook],
|
hooks: typing.List[Hook],
|
||||||
hints: dict,
|
hints: typing.Optional[typing.Mapping] = None,
|
||||||
):
|
):
|
||||||
kwargs = {"hook_context": hook_context, "hints": hints}
|
kwargs = {"hook_context": hook_context, "hints": hints}
|
||||||
_execute_hooks(
|
_execute_hooks(
|
||||||
|
|
@ -40,7 +40,7 @@ def after_hooks(
|
||||||
hook_context: HookContext,
|
hook_context: HookContext,
|
||||||
details: FlagEvaluationDetails,
|
details: FlagEvaluationDetails,
|
||||||
hooks: typing.List[Hook],
|
hooks: typing.List[Hook],
|
||||||
hints: dict,
|
hints: typing.Optional[typing.Mapping] = None,
|
||||||
):
|
):
|
||||||
kwargs = {"hook_context": hook_context, "details": details, "hints": hints}
|
kwargs = {"hook_context": hook_context, "details": details, "hints": hints}
|
||||||
_execute_hooks_unchecked(
|
_execute_hooks_unchecked(
|
||||||
|
|
@ -52,7 +52,7 @@ def before_hooks(
|
||||||
flag_type: FlagType,
|
flag_type: FlagType,
|
||||||
hook_context: HookContext,
|
hook_context: HookContext,
|
||||||
hooks: typing.List[Hook],
|
hooks: typing.List[Hook],
|
||||||
hints: dict,
|
hints: typing.Optional[typing.Mapping] = None,
|
||||||
) -> EvaluationContext:
|
) -> EvaluationContext:
|
||||||
kwargs = {"hook_context": hook_context, "hints": hints}
|
kwargs = {"hook_context": hook_context, "hints": hints}
|
||||||
executed_hooks = _execute_hooks_unchecked(
|
executed_hooks = _execute_hooks_unchecked(
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,12 @@ from open_feature.exception.exceptions import GeneralError
|
||||||
from open_feature.open_feature_client import OpenFeatureClient
|
from open_feature.open_feature_client import OpenFeatureClient
|
||||||
from open_feature.provider.provider import AbstractProvider
|
from open_feature.provider.provider import AbstractProvider
|
||||||
|
|
||||||
_provider = None
|
_provider: typing.Optional[AbstractProvider] = None
|
||||||
|
|
||||||
|
|
||||||
def get_client(name: str = None, version: str = None) -> OpenFeatureClient:
|
def get_client(
|
||||||
|
name: typing.Optional[str] = None, version: typing.Optional[str] = None
|
||||||
|
) -> OpenFeatureClient:
|
||||||
if _provider is None:
|
if _provider is None:
|
||||||
raise GeneralError(
|
raise GeneralError(
|
||||||
error_message="Provider not set. Call set_provider before using get_client"
|
error_message="Provider not set. Call set_provider before using get_client"
|
||||||
|
|
|
||||||
|
|
@ -24,17 +24,34 @@ from open_feature.open_feature_evaluation_context import api_evaluation_context
|
||||||
from open_feature.provider.no_op_provider import NoOpProvider
|
from open_feature.provider.no_op_provider import NoOpProvider
|
||||||
from open_feature.provider.provider import AbstractProvider
|
from open_feature.provider.provider import AbstractProvider
|
||||||
|
|
||||||
NUMERIC_TYPES = [FlagType.FLOAT, FlagType.INTEGER]
|
|
||||||
|
GetDetailCallable = typing.Union[
|
||||||
|
typing.Callable[
|
||||||
|
[str, bool, typing.Optional[EvaluationContext]], FlagEvaluationDetails[bool]
|
||||||
|
],
|
||||||
|
typing.Callable[
|
||||||
|
[str, int, typing.Optional[EvaluationContext]], FlagEvaluationDetails[int]
|
||||||
|
],
|
||||||
|
typing.Callable[
|
||||||
|
[str, float, typing.Optional[EvaluationContext]], FlagEvaluationDetails[float]
|
||||||
|
],
|
||||||
|
typing.Callable[
|
||||||
|
[str, str, typing.Optional[EvaluationContext]], FlagEvaluationDetails[str]
|
||||||
|
],
|
||||||
|
typing.Callable[
|
||||||
|
[str, dict, typing.Optional[EvaluationContext]], FlagEvaluationDetails[dict]
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class OpenFeatureClient:
|
class OpenFeatureClient:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: typing.Optional[str],
|
||||||
version: str,
|
version: typing.Optional[str],
|
||||||
context: EvaluationContext = None,
|
provider: AbstractProvider,
|
||||||
hooks: typing.List[Hook] = None,
|
context: typing.Optional[EvaluationContext] = None,
|
||||||
provider: AbstractProvider = None,
|
hooks: typing.Optional[typing.List[Hook]] = None,
|
||||||
):
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.version = version
|
self.version = version
|
||||||
|
|
@ -49,8 +66,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: bool,
|
default_value: bool,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.BOOLEAN,
|
FlagType.BOOLEAN,
|
||||||
|
|
@ -64,8 +81,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: bool,
|
default_value: bool,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.BOOLEAN,
|
FlagType.BOOLEAN,
|
||||||
|
|
@ -79,8 +96,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: str,
|
default_value: str,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.STRING,
|
FlagType.STRING,
|
||||||
|
|
@ -94,8 +111,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: str,
|
default_value: str,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.STRING,
|
FlagType.STRING,
|
||||||
|
|
@ -109,8 +126,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: int,
|
default_value: int,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> int:
|
) -> int:
|
||||||
return self.get_integer_details(
|
return self.get_integer_details(
|
||||||
flag_key,
|
flag_key,
|
||||||
|
|
@ -123,8 +140,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: int,
|
default_value: int,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.INTEGER,
|
FlagType.INTEGER,
|
||||||
|
|
@ -138,8 +155,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: float,
|
default_value: float,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> float:
|
) -> float:
|
||||||
return self.get_float_details(
|
return self.get_float_details(
|
||||||
flag_key,
|
flag_key,
|
||||||
|
|
@ -152,8 +169,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: float,
|
default_value: float,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.FLOAT,
|
FlagType.FLOAT,
|
||||||
|
|
@ -167,8 +184,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: dict,
|
default_value: dict,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.OBJECT,
|
FlagType.OBJECT,
|
||||||
|
|
@ -182,8 +199,8 @@ class OpenFeatureClient:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: dict,
|
default_value: dict,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
return self.evaluate_flag_details(
|
return self.evaluate_flag_details(
|
||||||
FlagType.OBJECT,
|
FlagType.OBJECT,
|
||||||
|
|
@ -198,8 +215,8 @@ class OpenFeatureClient:
|
||||||
flag_type: FlagType,
|
flag_type: FlagType,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: typing.Any,
|
default_value: typing.Any,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
flag_evaluation_options: FlagEvaluationOptions = None,
|
flag_evaluation_options: typing.Optional[FlagEvaluationOptions] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
"""
|
"""
|
||||||
Evaluate the flag requested by the user from the clients provider.
|
Evaluate the flag requested by the user from the clients provider.
|
||||||
|
|
@ -302,7 +319,7 @@ class OpenFeatureClient:
|
||||||
flag_type: FlagType,
|
flag_type: FlagType,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: typing.Any,
|
default_value: typing.Any,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
) -> FlagEvaluationDetails:
|
) -> FlagEvaluationDetails:
|
||||||
"""
|
"""
|
||||||
Encapsulated method to create a FlagEvaluationDetail from a specific provider.
|
Encapsulated method to create a FlagEvaluationDetail from a specific provider.
|
||||||
|
|
@ -324,14 +341,15 @@ class OpenFeatureClient:
|
||||||
logging.info("No provider configured, using no-op provider.")
|
logging.info("No provider configured, using no-op provider.")
|
||||||
self.provider = NoOpProvider()
|
self.provider = NoOpProvider()
|
||||||
|
|
||||||
get_details_callable = {
|
get_details_callables: typing.Mapping[FlagType, GetDetailCallable] = {
|
||||||
FlagType.BOOLEAN: self.provider.resolve_boolean_details,
|
FlagType.BOOLEAN: self.provider.resolve_boolean_details,
|
||||||
FlagType.INTEGER: self.provider.resolve_integer_details,
|
FlagType.INTEGER: self.provider.resolve_integer_details,
|
||||||
FlagType.FLOAT: self.provider.resolve_float_details,
|
FlagType.FLOAT: self.provider.resolve_float_details,
|
||||||
FlagType.OBJECT: self.provider.resolve_object_details,
|
FlagType.OBJECT: self.provider.resolve_object_details,
|
||||||
FlagType.STRING: self.provider.resolve_string_details,
|
FlagType.STRING: self.provider.resolve_string_details,
|
||||||
}.get(flag_type)
|
}
|
||||||
|
|
||||||
|
get_details_callable = get_details_callables.get(flag_type)
|
||||||
if not get_details_callable:
|
if not get_details_callable:
|
||||||
raise GeneralError(error_message="Unknown flag type")
|
raise GeneralError(error_message="Unknown flag type")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ class NoOpProvider(AbstractProvider):
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: bool,
|
default_value: bool,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[bool]:
|
||||||
return FlagEvaluationDetails(
|
return FlagEvaluationDetails(
|
||||||
flag_key=flag_key,
|
flag_key=flag_key,
|
||||||
value=default_value,
|
value=default_value,
|
||||||
|
|
@ -35,8 +35,8 @@ class NoOpProvider(AbstractProvider):
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: str,
|
default_value: str,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[str]:
|
||||||
return FlagEvaluationDetails(
|
return FlagEvaluationDetails(
|
||||||
flag_key=flag_key,
|
flag_key=flag_key,
|
||||||
value=default_value,
|
value=default_value,
|
||||||
|
|
@ -48,8 +48,8 @@ class NoOpProvider(AbstractProvider):
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: int,
|
default_value: int,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[int]:
|
||||||
return FlagEvaluationDetails(
|
return FlagEvaluationDetails(
|
||||||
flag_key=flag_key,
|
flag_key=flag_key,
|
||||||
value=default_value,
|
value=default_value,
|
||||||
|
|
@ -61,8 +61,8 @@ class NoOpProvider(AbstractProvider):
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: float,
|
default_value: float,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[float]:
|
||||||
return FlagEvaluationDetails(
|
return FlagEvaluationDetails(
|
||||||
flag_key=flag_key,
|
flag_key=flag_key,
|
||||||
value=default_value,
|
value=default_value,
|
||||||
|
|
@ -74,8 +74,8 @@ class NoOpProvider(AbstractProvider):
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: dict,
|
default_value: dict,
|
||||||
evaluation_context: EvaluationContext = None,
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[dict]:
|
||||||
return FlagEvaluationDetails(
|
return FlagEvaluationDetails(
|
||||||
flag_key=flag_key,
|
flag_key=flag_key,
|
||||||
value=default_value,
|
value=default_value,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import typing
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from open_feature.evaluation_context.evaluation_context import EvaluationContext
|
from open_feature.evaluation_context.evaluation_context import EvaluationContext
|
||||||
|
from open_feature.flag_evaluation.flag_evaluation_details import FlagEvaluationDetails
|
||||||
from open_feature.hooks.hook import Hook
|
from open_feature.hooks.hook import Hook
|
||||||
from open_feature.provider.metadata import Metadata
|
from open_feature.provider.metadata import Metadata
|
||||||
|
|
||||||
|
|
@ -20,8 +21,8 @@ class AbstractProvider:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: bool,
|
default_value: bool,
|
||||||
evaluation_context: EvaluationContext = EvaluationContext(),
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[bool]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
@ -29,8 +30,8 @@ class AbstractProvider:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: str,
|
default_value: str,
|
||||||
evaluation_context: EvaluationContext = EvaluationContext(),
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
@ -38,8 +39,8 @@ class AbstractProvider:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: int,
|
default_value: int,
|
||||||
evaluation_context: EvaluationContext = EvaluationContext(),
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[int]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
@ -47,8 +48,8 @@ class AbstractProvider:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: float,
|
default_value: float,
|
||||||
evaluation_context: EvaluationContext = EvaluationContext(),
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[float]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
@ -56,6 +57,6 @@ class AbstractProvider:
|
||||||
self,
|
self,
|
||||||
flag_key: str,
|
flag_key: str,
|
||||||
default_value: dict,
|
default_value: dict,
|
||||||
evaluation_context: EvaluationContext = EvaluationContext(),
|
evaluation_context: typing.Optional[EvaluationContext] = None,
|
||||||
):
|
) -> FlagEvaluationDetails[dict]:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ def test_should_handle_an_open_feature_exception_thrown_by_a_provider(
|
||||||
# Given
|
# Given
|
||||||
exception_hook = MagicMock(spec=Hook)
|
exception_hook = MagicMock(spec=Hook)
|
||||||
exception_hook.after.side_effect = OpenFeatureError(
|
exception_hook.after.side_effect = OpenFeatureError(
|
||||||
"error_message", ErrorCode.GENERAL
|
ErrorCode.GENERAL, "error_message"
|
||||||
)
|
)
|
||||||
no_op_provider_client.add_hooks([exception_hook])
|
no_op_provider_client.add_hooks([exception_hook])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue