Skip to content

Commit b0f2c61

Browse files
authored
feat!: Bump openfeature-sdk to v0.8+ (#34)
1 parent 411266e commit b0f2c61

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

ld_openfeature/impl/context_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from logging import getLogger
2-
from typing import Any, Dict, List, Optional
2+
from typing import Any, Dict, List, Mapping, Optional
33

44
from ldclient.context import Context, ContextBuilder, ContextMultiBuilder
5-
from openfeature.evaluation_context import EvaluationContext
5+
from openfeature.evaluation_context import EvaluationContext, EvaluationContextAttribute
66

77

88
logger = getLogger("launchdarkly-openfeature-server")
@@ -78,7 +78,7 @@ def __build_multi_context(self, context: EvaluationContext) -> Context:
7878

7979
return builder.build()
8080

81-
def __build_single_context(self, attributes: Dict, kind: str, key: str) -> Context:
81+
def __build_single_context(self, attributes: Mapping[str, EvaluationContextAttribute], kind: str, key: str) -> Context:
8282
builder = ContextBuilder(key)
8383
builder.kind(kind)
8484

ld_openfeature/provider.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import threading
2-
from typing import Any, List, Optional, Union
2+
from typing import Any, List, Mapping, Optional, Sequence, Union
33

44
from ldclient.evaluation import EvaluationDetail
55
from ldclient import LDClient, Config
66
from ldclient.interfaces import DataSourceStatus, FlagChange, DataSourceState
77
from openfeature.evaluation_context import EvaluationContext
88
from openfeature.exception import ErrorCode, ProviderFatalError
9-
from openfeature.flag_evaluation import FlagResolutionDetails, FlagType, Reason
9+
from openfeature.flag_evaluation import FlagResolutionDetails, FlagType, FlagValueType, Reason
1010
from openfeature.hook import Hook
1111
from openfeature.provider.metadata import Metadata
1212
from openfeature.provider import AbstractProvider
@@ -133,7 +133,9 @@ def resolve_float_details(
133133
def resolve_object_details(
134134
self,
135135
flag_key: str,
136-
default_value: Union[dict, list],
136+
default_value: Union[
137+
Sequence[FlagValueType], Mapping[str, FlagValueType]
138+
],
137139
evaluation_context: Optional[EvaluationContext] = None,
138140
) -> FlagResolutionDetails[Union[dict, list]]:
139141
"""Resolves the flag value for the provided flag key as a list or dictionary"""
@@ -154,15 +156,15 @@ def __resolve_value(self, flag_type: FlagType, flag_key: str, default_value: Any
154156
resolved_value = self.__validate_and_cast_value(flag_type, result.value)
155157
if resolved_value is None:
156158
return self.__mismatched_type_details(default_value)
157-
159+
158160
resolved_detail = EvaluationDetail(
159161
value=resolved_value,
160162
variation_index=result.variation_index,
161163
reason=result.reason,
162164
)
163-
165+
164166
return self.__details_converter.to_resolution_details(resolved_detail)
165-
167+
166168
def __validate_and_cast_value(self, flag_type: FlagType, value: Any):
167169
"""Serializes the raw flag value to the expected type based on flag_type."""
168170
if flag_type == FlagType.BOOLEAN and isinstance(value, bool):
@@ -175,7 +177,7 @@ def __validate_and_cast_value(self, flag_type: FlagType, value: Any):
175177
return float(value)
176178
elif flag_type == FlagType.OBJECT and isinstance(value, (dict, list)):
177179
return value
178-
return None
180+
return None
179181

180182
@staticmethod
181183
def __mismatched_type_details(default_value: Any) -> FlagResolutionDetails:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ packages = [
2828

2929
[tool.poetry.dependencies]
3030
python = "^3.9"
31-
openfeature-sdk = ">=0.7.0,<1"
31+
openfeature-sdk = ">=0.8.0,<1"
3232
launchdarkly-server-sdk = "<10"
3333

3434

tests/impl/test_context_converter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Mapping
12
import pytest
2-
from openfeature.evaluation_context import EvaluationContext
3+
from openfeature.evaluation_context import EvaluationContext, EvaluationContextAttribute
34

45
from ld_openfeature.impl.context_converter import EvaluationContextConverter
56

@@ -49,7 +50,7 @@ def test_invalid_private_attribute_types_are_ignored(context_converter: Evaluati
4950

5051

5152
def test_create_multi_context_with_invalid_targeting_key(context_converter: EvaluationContextConverter):
52-
attributes = {
53+
attributes: Mapping[str, EvaluationContextAttribute] = {
5354
'kind': 'multi',
5455
'user': {'targetingKey': False, 'key': 'user-key', 'name': 'User name'},
5556
'org': {'key': 'org-key', 'name': 'Org name'},
@@ -142,7 +143,7 @@ def test_private_attributes_are_processed_correctly(context_converter: Evaluatio
142143

143144

144145
def test_can_create_multi_kind_context(context_converter: EvaluationContextConverter):
145-
attributes = {
146+
attributes: Mapping[str, EvaluationContextAttribute] = {
146147
'kind': 'multi',
147148
'user': {'key': 'user-key', 'name': 'User name'},
148149
'org': {'key': 'org-key', 'name': 'Org name'},
@@ -167,7 +168,7 @@ def test_can_create_multi_kind_context(context_converter: EvaluationContextConve
167168

168169

169170
def test_can_multi_kind_ignores_kind_attribute(context_converter: EvaluationContextConverter):
170-
attributes = {
171+
attributes: Mapping[str, EvaluationContextAttribute] = {
171172
'kind': 'multi',
172173
'user': {'key': 'user-key', 'kind': 'device', 'name': 'User name'},
173174
'org': {'key': 'org-key', 'name': 'Org name'},
@@ -192,7 +193,7 @@ def test_can_multi_kind_ignores_kind_attribute(context_converter: EvaluationCont
192193

193194

194195
def test_multi_context_discards_invalid_single_kind(context_converter: EvaluationContextConverter):
195-
attributes = {
196+
attributes: Mapping[str, EvaluationContextAttribute] = {
196197
'kind': 'multi',
197198
'user': False,
198199
'org': {'key': 'org-key', 'name': 'Org name'},
@@ -208,7 +209,7 @@ def test_multi_context_discards_invalid_single_kind(context_converter: Evaluatio
208209

209210

210211
def test_handles_invalid_nested_contexts(context_converter: EvaluationContextConverter):
211-
attributes = {
212+
attributes: Mapping[str, EvaluationContextAttribute] = {
212213
'kind': 'multi',
213214
'user': 'invalid format',
214215
'org': False

0 commit comments

Comments
 (0)