Skip to content

Commit 21e931f

Browse files
refactor: move InternalHookProvider to provider/_protocols.py
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
1 parent f87d948 commit 21e931f

2 files changed

Lines changed: 39 additions & 32 deletions

File tree

openfeature/provider/__init__.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from openfeature.hook import Hook
1212
from openfeature.track import TrackingEventDetails
1313

14+
from ._protocols import InternalHookProvider
1415
from .metadata import Metadata
1516

1617
if typing.TYPE_CHECKING:
@@ -137,38 +138,6 @@ def track(
137138
) -> None: ...
138139

139140

140-
@typing.runtime_checkable
141-
class InternalHookProvider(typing.Protocol):
142-
"""Protocol for providers that manage their own provider hook execution.
143-
144-
Providers implementing this protocol (e.g. MultiProvider) handle provider
145-
hook lifecycle internally. The client will skip its own provider hook
146-
invocations and instead delegate to the provider via the set/reset methods.
147-
148-
The registry will also use get_status() from this protocol instead of its
149-
own internal status tracking for providers that implement it.
150-
151-
Implementations must set ``_is_internal_hook_provider = True`` as a class
152-
attribute. This marker is checked alongside ``isinstance`` to avoid false
153-
positives from duck-typed objects (e.g. ``Mock``).
154-
"""
155-
156-
_is_internal_hook_provider: typing.ClassVar[bool]
157-
158-
def uses_internal_provider_hooks(self) -> bool: ...
159-
160-
def set_internal_provider_hook_runtime(
161-
self,
162-
flag_type: typing.Any,
163-
client_metadata: typing.Any,
164-
hook_hints: typing.Any,
165-
) -> typing.Any: ...
166-
167-
def reset_internal_provider_hook_runtime(self, token: typing.Any) -> None: ...
168-
169-
def get_status(self) -> ProviderStatus: ...
170-
171-
172141
class AbstractProvider(FeatureProvider):
173142
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
174143
# this makes sure to invoke the parent of `FeatureProvider` -> `object`

openfeature/provider/_protocols.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import annotations
2+
3+
import typing
4+
5+
if typing.TYPE_CHECKING:
6+
from openfeature.provider import ProviderStatus
7+
8+
9+
@typing.runtime_checkable
10+
class InternalHookProvider(typing.Protocol):
11+
"""Protocol for providers that manage their own provider hook execution.
12+
13+
Providers implementing this protocol (e.g. MultiProvider) handle provider
14+
hook lifecycle internally. The client will skip its own provider hook
15+
invocations and instead delegate to the provider via the set/reset methods.
16+
17+
The registry will also use get_status() from this protocol instead of its
18+
own internal status tracking for providers that implement it.
19+
20+
Implementations must set ``_is_internal_hook_provider = True`` as a class
21+
attribute. This marker is checked alongside ``isinstance`` to avoid false
22+
positives from duck-typed objects (e.g. ``Mock``).
23+
"""
24+
25+
_is_internal_hook_provider: typing.ClassVar[bool]
26+
27+
def uses_internal_provider_hooks(self) -> bool: ...
28+
29+
def set_internal_provider_hook_runtime(
30+
self,
31+
flag_type: typing.Any,
32+
client_metadata: typing.Any,
33+
hook_hints: typing.Any,
34+
) -> typing.Any: ...
35+
36+
def reset_internal_provider_hook_runtime(self, token: typing.Any) -> None: ...
37+
38+
def get_status(self) -> ProviderStatus: ...

0 commit comments

Comments
 (0)