forked from DevCycleHQ/python-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature.py
More file actions
33 lines (29 loc) · 852 Bytes
/
Copy pathfeature.py
File metadata and controls
33 lines (29 loc) · 852 Bytes
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
# ruff: noqa: N815
from dataclasses import dataclass
from typing import Optional
@dataclass(order=False)
class Feature:
_id: str
key: str
type: str
_variation: str
variationName: Optional[str] = None
variationKey: Optional[str] = None
evalReason: Optional[str] = None
def to_json(self):
return {
key: getattr(self, key)
for key in self.__dataclass_fields__
if getattr(self, key) is not None
}
@classmethod
def from_json(cls, data: dict) -> "Feature":
return cls(
_id=data["_id"],
key=data["key"],
type=data["type"],
_variation=data["_variation"],
variationName=data["variationName"],
variationKey=data["variationKey"],
evalReason=data.get("evalReason"),
)