-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheval_hook_context.py
More file actions
28 lines (24 loc) · 928 Bytes
/
eval_hook_context.py
File metadata and controls
28 lines (24 loc) · 928 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
from typing import Any, Optional
from dataclasses import dataclass
from devcycle_python_sdk.models.user import DevCycleUser
from devcycle_python_sdk.models.config_metadata import ConfigMetadata
@dataclass
class HookContext:
key: str
user: DevCycleUser
default_value: Any
config_metadata: Optional[ConfigMetadata] = None
def to_json(self):
result = {}
for field_name in self.__dataclass_fields__:
value = getattr(self, field_name)
if value is not None:
if field_name == "config_metadata" and isinstance(
value, ConfigMetadata
):
result[field_name] = value.to_json()
elif field_name == "user" and isinstance(value, DevCycleUser):
result[field_name] = value.to_json()
else:
result[field_name] = value
return result