forked from open-feature/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag_evaluation.py
60 lines (44 loc) · 1.45 KB
/
flag_evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from __future__ import annotations
import typing
from dataclasses import dataclass, field
from open_feature._backports.strenum import StrEnum
from open_feature.exception import ErrorCode
if typing.TYPE_CHECKING: # resolves a circular dependency in type annotations
from open_feature.hook import Hook
class FlagType(StrEnum):
BOOLEAN = "BOOLEAN"
STRING = "STRING"
OBJECT = "OBJECT"
FLOAT = "FLOAT"
INTEGER = "INTEGER"
class Reason(StrEnum):
CACHED = "CACHED"
DEFAULT = "DEFAULT"
DISABLED = "DISABLED"
ERROR = "ERROR"
STATIC = "STATIC"
SPLIT = "SPLIT"
TARGETING_MATCH = "TARGETING_MATCH"
UNKNOWN = "UNKNOWN"
T = typing.TypeVar("T", covariant=True)
@dataclass
class FlagEvaluationDetails(typing.Generic[T]):
flag_key: str
value: T
variant: typing.Optional[str] = None
reason: typing.Optional[Reason] = None
error_code: typing.Optional[ErrorCode] = None
error_message: typing.Optional[str] = None
@dataclass
class FlagEvaluationOptions:
hooks: typing.List[Hook] = field(default_factory=list)
hook_hints: dict = field(default_factory=dict)
U = typing.TypeVar("U", covariant=True)
@dataclass
class FlagResolutionDetails(typing.Generic[U]):
value: U
error_code: typing.Optional[ErrorCode] = None
error_message: typing.Optional[str] = None
reason: typing.Optional[Reason] = None
variant: typing.Optional[str] = None
flag_metadata: typing.Optional[str] = None