Skip to content

Commit 2a4b8fb

Browse files
committed
feat: add context_publisher setter and deprecate context_event_handler
Add context_publisher as the primary field in ABsmartlyConfig, replacing context_event_handler. The old name is kept as a deprecated property that delegates to context_publisher for backward compatibility. Export ContextPublisher from the public SDK API.
1 parent 54ffc14 commit 2a4b8fb

4 files changed

Lines changed: 51 additions & 9 deletions

File tree

sdk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sdk.context import Context
66
from sdk.context_config import ContextConfig
77
from sdk.context_event_logger import ContextEventLogger
8+
from sdk.context_publisher import ContextPublisher
89
from sdk.default_http_client import DefaultHTTPClient
910
from sdk.default_http_client_config import DefaultHTTPClientConfig
1011

@@ -18,6 +19,7 @@
1819
"Context",
1920
"ContextConfig",
2021
"ContextEventLogger",
22+
"ContextPublisher",
2123
"DefaultHTTPClient",
2224
"DefaultHTTPClientConfig",
2325
]

sdk/absmartly.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from concurrent.futures import Future
23
from typing import Optional
34

@@ -66,21 +67,21 @@ def create(
6667

6768
def __init__(self, config: ABsmartlyConfig):
6869
self.context_data_provider = config.context_data_provider
69-
self.context_event_handler = config.context_event_handler
70+
self.context_publisher = config.context_publisher
7071
self.context_event_logger = config.context_event_logger
7172
self.variable_parser = config.variable_parser
7273
self.audience_deserializer = config.audience_deserializer
7374

7475
if self.context_data_provider is None or \
75-
self.context_event_handler is None:
76+
self.context_publisher is None:
7677
self.client = config.client
7778

7879
if self.context_data_provider is None:
7980
self.context_data_provider = \
8081
DefaultContextDataProvider(self.client)
8182

82-
if self.context_event_handler is None:
83-
self.context_event_handler = \
83+
if self.context_publisher is None:
84+
self.context_publisher = \
8485
DefaultContextPublisher(self.client)
8586

8687
if self.variable_parser is None:
@@ -89,6 +90,27 @@ def __init__(self, config: ABsmartlyConfig):
8990
if self.audience_deserializer is None:
9091
self.audience_deserializer = DefaultAudienceDeserializer()
9192

93+
def __getattr__(self, name):
94+
if name == "context_event_handler":
95+
warnings.warn(
96+
"context_event_handler is deprecated, use context_publisher instead",
97+
DeprecationWarning,
98+
stacklevel=2,
99+
)
100+
return self.context_publisher
101+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
102+
103+
def __setattr__(self, name, value):
104+
if name == "context_event_handler":
105+
warnings.warn(
106+
"context_event_handler is deprecated, use context_publisher instead",
107+
DeprecationWarning,
108+
stacklevel=2,
109+
)
110+
super().__setattr__("context_publisher", value)
111+
else:
112+
super().__setattr__(name, value)
113+
92114
def get_context_data(self) -> Future[Optional[ContextData]]:
93115
return self.context_data_provider.get_context_data()
94116

@@ -97,7 +119,7 @@ def create_context(self, config: ContextConfig) -> Context:
97119
config,
98120
self.context_data_provider.get_context_data(),
99121
self.context_data_provider,
100-
self.context_event_handler,
122+
self.context_publisher,
101123
self.context_event_logger,
102124
self.variable_parser,
103125
AudienceMatcher(self.audience_deserializer))
@@ -110,7 +132,7 @@ def create_context_with(self,
110132
return Context(SystemClockUTC(), config,
111133
future_data,
112134
self.context_data_provider,
113-
self.context_event_handler,
135+
self.context_publisher,
114136
self.context_event_logger,
115137
self.variable_parser,
116138
AudienceMatcher(self.audience_deserializer))

sdk/absmartly_config.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Optional
23

34
from sdk.audience_deserializer import AudienceDeserializer
@@ -10,16 +11,33 @@
1011

1112
class ABsmartlyConfig:
1213
context_data_provider: Optional[ContextDataProvider] = None
13-
context_event_handler: Optional[ContextPublisher] = None
14+
context_publisher: Optional[ContextPublisher] = None
1415
context_event_logger: Optional[ContextEventLogger] = None
1516
audience_deserializer: Optional[AudienceDeserializer] = None
1617
client: Optional[Client] = None
1718
variable_parser: Optional[VariableParser] = None
1819

20+
@property
21+
def context_event_handler(self) -> Optional[ContextPublisher]:
22+
warnings.warn(
23+
"context_event_handler is deprecated, use context_publisher instead",
24+
DeprecationWarning,
25+
stacklevel=2,
26+
)
27+
return self.context_publisher
28+
29+
@context_event_handler.setter
30+
def context_event_handler(self, value: Optional[ContextPublisher]):
31+
warnings.warn(
32+
"context_event_handler is deprecated, use context_publisher instead",
33+
DeprecationWarning,
34+
stacklevel=2,
35+
)
36+
self.context_publisher = value
37+
1938

2039
class ABSmartlyConfig(ABsmartlyConfig):
2140
def __init__(self, *args, **kwargs):
22-
import warnings
2341
warnings.warn(
2442
"ABSmartlyConfig is deprecated, use ABsmartlyConfig instead",
2543
DeprecationWarning,

test/test_named_param_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_create_with_all_required_params(self):
1919

2020
self.assertIsNotNone(sdk)
2121
self.assertIsNotNone(sdk.context_data_provider)
22-
self.assertIsNotNone(sdk.context_event_handler)
22+
self.assertIsNotNone(sdk.context_publisher)
2323
self.assertIsNotNone(sdk.variable_parser)
2424
self.assertIsNotNone(sdk.audience_deserializer)
2525

0 commit comments

Comments
 (0)