Skip to content

Commit cecb0c9

Browse files
committed
feat(provider): improve type safety
Signed-off-by: Kiki L Hakiem <[email protected]>
1 parent f242754 commit cecb0c9

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

providers/openfeature-provider-unleash/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unleash Provider for OpenFeature
22

3-
This provider is designed to use [Unleash](https://unleash.io/).
3+
This provider is designed to use [Unleash](https://www.getunleash.io/).
44

55
## Installation
66

@@ -18,9 +18,9 @@ from openfeature.contrib.provider.unleash import UnleashProvider
1818

1919
# Initialize the provider with your Unleash configuration
2020
provider = UnleashProvider(
21-
url="https://your-unleash-instance.com",
21+
url="https://my-unleash-instance.com",
2222
app_name="my-python-app",
23-
api_token="your-api-token"
23+
api_token="my-api-token"
2424
)
2525

2626
# Initialize the provider (required before use)
@@ -127,7 +127,7 @@ is_enabled = client.get_boolean_value("my-feature", False)
127127
print(f"Feature is enabled: {is_enabled}")
128128

129129
# String flag evaluation with context
130-
context = {"userId": "user123", "sessionId": "session456"}
130+
context = EvaluationContext(targeting_key="user123", attributes={"sessionId": "session456"})
131131
variant = client.get_string_value("my-variant-flag", "default", context)
132132
print(f"Variant: {variant}")
133133

@@ -149,13 +149,13 @@ provider.shutdown()
149149
### Running tests
150150

151151
```bash
152-
pytest
152+
uv run test --frozen
153153
```
154154

155155
### Type checking
156156

157157
```bash
158-
mypy src/
158+
uv run mypy-check
159159
```
160160

161161
## License

providers/openfeature-provider-unleash/src/openfeature/contrib/provider/unleash/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from UnleashClient.events import BaseEvent, UnleashFetchedEvent, UnleashReadyEvent
66
from openfeature.event import ProviderEvent
7+
from openfeature.provider import Metadata
78

89

910
class UnleashProvider(Protocol):
@@ -14,7 +15,7 @@ def _event_handlers(self) -> dict[ProviderEvent, List[Callable]]:
1415
"""Event handlers dictionary."""
1516
...
1617

17-
def get_metadata(self) -> Any:
18+
def get_metadata(self) -> Metadata:
1819
"""Get provider metadata."""
1920
...
2021

providers/openfeature-provider-unleash/src/openfeature/contrib/provider/unleash/flag_evaluation.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Any, Callable, Optional, Protocol
44

5+
from UnleashClient import UnleashClient
56
from openfeature.evaluation_context import EvaluationContext
67
from openfeature.exception import (
78
FlagNotFoundError,
@@ -17,7 +18,7 @@ class UnleashProvider(Protocol):
1718
"""Protocol defining the interface needed by FlagEvaluator."""
1819

1920
@property
20-
def client(self) -> Optional[Any]: ...
21+
def client(self) -> Optional[UnleashClient]: ...
2122

2223
@property
2324
def app_name(self) -> str: ...
@@ -196,11 +197,7 @@ def _resolve_variant_flag(
196197
value = value_converter(payload_value)
197198
return FlagResolutionDetails(
198199
value=value,
199-
reason=(
200-
Reason.TARGETING_MATCH
201-
if value != default_value
202-
else Reason.DEFAULT
203-
),
200+
reason=Reason.TARGETING_MATCH,
204201
variant=variant.get("name"),
205202
error_code=None,
206203
error_message=None,

providers/openfeature-provider-unleash/src/openfeature/contrib/provider/unleash/tracking.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Optional, Protocol
44
import uuid
55

6+
from UnleashClient import UnleashClient
67
from UnleashClient.events import UnleashEvent, UnleashEventType
78
from openfeature.evaluation_context import EvaluationContext
89

@@ -11,7 +12,7 @@ class UnleashProvider(Protocol):
1112
"""Protocol defining the interface needed by Tracker."""
1213

1314
@property
14-
def client(self) -> Optional[Any]: ...
15+
def client(self) -> Optional[UnleashClient]: ...
1516

1617
def _build_unleash_context(
1718
self, evaluation_context: Optional[EvaluationContext] = None

providers/openfeature-provider-unleash/tests/test_flag_evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def test_variant_flag_scenarios():
441441
}
442442
result = provider.resolve_string_details("test_flag", "default")
443443
assert result.value == "default"
444-
assert result.reason == Reason.DEFAULT
444+
assert result.reason == Reason.TARGETING_MATCH
445445
assert result.variant == "test-variant"
446446

447447
provider.shutdown()

0 commit comments

Comments
 (0)