Skip to content

Commit a238c47

Browse files
committed
uv run ruff check --fix
1 parent 2db3d7c commit a238c47

File tree

17 files changed

+210
-246
lines changed

17 files changed

+210
-246
lines changed

openfeature/api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import typing
21

32
from openfeature import _event_support
43
from openfeature.client import OpenFeatureClient
@@ -40,13 +39,13 @@
4039

4140

4241
def get_client(
43-
domain: typing.Optional[str] = None, version: typing.Optional[str] = None
42+
domain: str | None = None, version: str | None = None
4443
) -> OpenFeatureClient:
4544
return OpenFeatureClient(domain=domain, version=version)
4645

4746

4847
def set_provider(
49-
provider: FeatureProvider, domain: typing.Optional[str] = None
48+
provider: FeatureProvider, domain: str | None = None
5049
) -> None:
5150
if domain is None:
5251
provider_registry.set_default_provider(provider)
@@ -59,7 +58,7 @@ def clear_providers() -> None:
5958
_event_support.clear()
6059

6160

62-
def get_provider_metadata(domain: typing.Optional[str] = None) -> Metadata:
61+
def get_provider_metadata(domain: str | None = None) -> Metadata:
6362
return provider_registry.get_provider(domain).get_metadata()
6463

6564

openfeature/client.py

Lines changed: 92 additions & 106 deletions
Large diffs are not rendered by default.

openfeature/evaluation_context/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
@dataclass
2525
class EvaluationContext:
26-
targeting_key: typing.Optional[str] = None
26+
targeting_key: str | None = None
2727
attributes: Mapping[str, EvaluationContextAttribute] = field(default_factory=dict)
2828

2929
def merge(self, ctx2: EvaluationContext) -> EvaluationContext:

openfeature/event.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import typing
43
from collections.abc import Callable
54
from dataclasses import dataclass, field
65
from enum import Enum
@@ -19,21 +18,21 @@ class ProviderEvent(Enum):
1918

2019
@dataclass
2120
class ProviderEventDetails:
22-
flags_changed: typing.Optional[list[str]] = None
23-
message: typing.Optional[str] = None
24-
error_code: typing.Optional[ErrorCode] = None
25-
metadata: dict[str, typing.Union[bool, str, int, float]] = field(
21+
flags_changed: list[str] | None = None
22+
message: str | None = None
23+
error_code: ErrorCode | None = None
24+
metadata: dict[str, bool | str | int | float] = field(
2625
default_factory=dict
2726
)
2827

2928

3029
@dataclass
3130
class EventDetails(ProviderEventDetails):
3231
provider_name: str = ""
33-
flags_changed: typing.Optional[list[str]] = None
34-
message: typing.Optional[str] = None
35-
error_code: typing.Optional[ErrorCode] = None
36-
metadata: dict[str, typing.Union[bool, str, int, float]] = field(
32+
flags_changed: list[str] | None = None
33+
message: str | None = None
34+
error_code: ErrorCode | None = None
35+
metadata: dict[str, bool | str | int | float] = field(
3736
default_factory=dict
3837
)
3938

openfeature/exception.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import typing
43
from collections.abc import Callable, Mapping
54

65
from openfeature._backports.strenum import StrEnum
@@ -26,7 +25,7 @@ class OpenFeatureError(Exception):
2625
"""
2726

2827
def __init__(
29-
self, error_code: ErrorCode, error_message: typing.Optional[str] = None
28+
self, error_code: ErrorCode, error_message: str | None = None
3029
):
3130
"""
3231
Constructor for the generic OpenFeatureError.
@@ -43,7 +42,7 @@ class ProviderNotReadyError(OpenFeatureError):
4342
This exception should be raised when the provider is not ready to be used.
4443
"""
4544

46-
def __init__(self, error_message: typing.Optional[str] = None):
45+
def __init__(self, error_message: str | None = None):
4746
"""
4847
Constructor for the ProviderNotReadyError. The error code for this type of
4948
exception is ErrorCode.PROVIDER_NOT_READY.
@@ -58,7 +57,7 @@ class ProviderFatalError(OpenFeatureError):
5857
This exception should be raised when the provider encounters a fatal error.
5958
"""
6059

61-
def __init__(self, error_message: typing.Optional[str] = None):
60+
def __init__(self, error_message: str | None = None):
6261
"""
6362
Constructor for the ProviderFatalError. The error code for this type of
6463
exception is ErrorCode.PROVIDER_FATAL.
@@ -74,7 +73,7 @@ class FlagNotFoundError(OpenFeatureError):
7473
key provided by the user.
7574
"""
7675

77-
def __init__(self, error_message: typing.Optional[str] = None):
76+
def __init__(self, error_message: str | None = None):
7877
"""
7978
Constructor for the FlagNotFoundError. The error code for
8079
this type of exception is ErrorCode.FLAG_NOT_FOUND.
@@ -90,7 +89,7 @@ class GeneralError(OpenFeatureError):
9089
feature python sdk.
9190
"""
9291

93-
def __init__(self, error_message: typing.Optional[str] = None):
92+
def __init__(self, error_message: str | None = None):
9493
"""
9594
Constructor for the GeneralError. The error code for this type of exception
9695
is ErrorCode.GENERAL.
@@ -106,7 +105,7 @@ class ParseError(OpenFeatureError):
106105
be parsed into a FlagEvaluationDetails object.
107106
"""
108107

109-
def __init__(self, error_message: typing.Optional[str] = None):
108+
def __init__(self, error_message: str | None = None):
110109
"""
111110
Constructor for the ParseError. The error code for this type of exception
112111
is ErrorCode.PARSE_ERROR.
@@ -122,7 +121,7 @@ class TypeMismatchError(OpenFeatureError):
122121
not match the type requested by the user.
123122
"""
124123

125-
def __init__(self, error_message: typing.Optional[str] = None):
124+
def __init__(self, error_message: str | None = None):
126125
"""
127126
Constructor for the TypeMismatchError. The error code for this type of
128127
exception is ErrorCode.TYPE_MISMATCH.
@@ -138,7 +137,7 @@ class TargetingKeyMissingError(OpenFeatureError):
138137
but one was not provided in the evaluation context.
139138
"""
140139

141-
def __init__(self, error_message: typing.Optional[str] = None):
140+
def __init__(self, error_message: str | None = None):
142141
"""
143142
Constructor for the TargetingKeyMissingError. The error code for this type of
144143
exception is ErrorCode.TARGETING_KEY_MISSING.
@@ -154,7 +153,7 @@ class InvalidContextError(OpenFeatureError):
154153
requirements.
155154
"""
156155

157-
def __init__(self, error_message: typing.Optional[str]):
156+
def __init__(self, error_message: str | None):
158157
"""
159158
Constructor for the InvalidContextError. The error code for this type of
160159
exception is ErrorCode.INVALID_CONTEXT.

openfeature/flag_evaluation.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Reason(StrEnum):
4242
UNKNOWN = "UNKNOWN"
4343

4444

45-
FlagMetadata = Mapping[str, typing.Union[bool, int, float, str]]
45+
FlagMetadata = Mapping[str, bool | int | float | str]
4646
FlagValueType = typing.Union[
4747
bool,
4848
int,
@@ -59,13 +59,13 @@ class Reason(StrEnum):
5959
class FlagEvaluationDetails(typing.Generic[T_co]):
6060
flag_key: str
6161
value: T_co
62-
variant: typing.Optional[str] = None
62+
variant: str | None = None
6363
flag_metadata: FlagMetadata = field(default_factory=dict)
64-
reason: typing.Optional[typing.Union[str, Reason]] = None
65-
error_code: typing.Optional[ErrorCode] = None
66-
error_message: typing.Optional[str] = None
64+
reason: str | Reason | None = None
65+
error_code: ErrorCode | None = None
66+
error_message: str | None = None
6767

68-
def get_exception(self) -> typing.Optional[OpenFeatureError]:
68+
def get_exception(self) -> OpenFeatureError | None:
6969
if self.error_code:
7070
return ErrorCode.to_exception(self.error_code, self.error_message or "")
7171
return None
@@ -83,10 +83,10 @@ class FlagEvaluationOptions:
8383
@dataclass
8484
class FlagResolutionDetails(typing.Generic[U_co]):
8585
value: U_co
86-
error_code: typing.Optional[ErrorCode] = None
87-
error_message: typing.Optional[str] = None
88-
reason: typing.Optional[typing.Union[str, Reason]] = None
89-
variant: typing.Optional[str] = None
86+
error_code: ErrorCode | None = None
87+
error_message: str | None = None
88+
reason: str | Reason | None = None
89+
variant: str | None = None
9090
flag_metadata: FlagMetadata = field(default_factory=dict)
9191

9292
def raise_for_error(self) -> None:

openfeature/hook/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def __init__( # noqa: PLR0913
4444
flag_type: FlagType,
4545
default_value: FlagValueType,
4646
evaluation_context: EvaluationContext,
47-
client_metadata: typing.Optional[ClientMetadata] = None,
48-
provider_metadata: typing.Optional[Metadata] = None,
49-
hook_data: typing.Optional[HookData] = None,
47+
client_metadata: ClientMetadata | None = None,
48+
provider_metadata: Metadata | None = None,
49+
hook_data: HookData | None = None,
5050
):
5151
self.flag_key = flag_key
5252
self.flag_type = flag_type
@@ -85,7 +85,7 @@ def __setattr__(self, key: str, value: typing.Any) -> None:
8585
class Hook:
8686
def before(
8787
self, hook_context: HookContext, hints: HookHints
88-
) -> typing.Optional[EvaluationContext]:
88+
) -> EvaluationContext | None:
8989
"""
9090
Runs before flag is resolved.
9191

openfeature/hook/_hook_support.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def error_hooks(
1313
flag_type: FlagType,
1414
exception: Exception,
1515
hooks_and_context: list[tuple[Hook, HookContext]],
16-
hints: typing.Optional[HookHints] = None,
16+
hints: HookHints | None = None,
1717
) -> None:
1818
kwargs = {"exception": exception, "hints": hints}
1919
_execute_hooks(
@@ -28,7 +28,7 @@ def after_all_hooks(
2828
flag_type: FlagType,
2929
details: FlagEvaluationDetails[typing.Any],
3030
hooks_and_context: list[tuple[Hook, HookContext]],
31-
hints: typing.Optional[HookHints] = None,
31+
hints: HookHints | None = None,
3232
) -> None:
3333
kwargs = {"details": details, "hints": hints}
3434
_execute_hooks(
@@ -43,7 +43,7 @@ def after_hooks(
4343
flag_type: FlagType,
4444
details: FlagEvaluationDetails[typing.Any],
4545
hooks_and_context: list[tuple[Hook, HookContext]],
46-
hints: typing.Optional[HookHints] = None,
46+
hints: HookHints | None = None,
4747
) -> None:
4848
kwargs = {"details": details, "hints": hints}
4949
_execute_hooks_unchecked(
@@ -57,7 +57,7 @@ def after_hooks(
5757
def before_hooks(
5858
flag_type: FlagType,
5959
hooks_and_context: list[tuple[Hook, HookContext]],
60-
hints: typing.Optional[HookHints] = None,
60+
hints: HookHints | None = None,
6161
) -> EvaluationContext:
6262
kwargs = {"hints": hints}
6363
executed_hooks = _execute_hooks_unchecked(
@@ -79,7 +79,7 @@ def _execute_hooks(
7979
hooks_and_context: list[tuple[Hook, HookContext]],
8080
hook_method: HookType,
8181
**kwargs: typing.Any,
82-
) -> list[typing.Optional[EvaluationContext]]:
82+
) -> list[EvaluationContext | None]:
8383
"""
8484
Run multiple hooks of any hook type. All of these hooks will be run through an
8585
exception check.
@@ -102,7 +102,7 @@ def _execute_hooks_unchecked(
102102
hooks_and_context: list[tuple[Hook, HookContext]],
103103
hook_method: HookType,
104104
**kwargs: typing.Any,
105-
) -> list[typing.Optional[EvaluationContext]]:
105+
) -> list[EvaluationContext | None]:
106106
"""
107107
Execute a single hook without checking whether an exception is thrown. This is
108108
used in the before and after hooks since any exception will be caught in the
@@ -123,7 +123,7 @@ def _execute_hooks_unchecked(
123123

124124
def _execute_hook_checked(
125125
hook: Hook, hook_method: HookType, **kwargs: typing.Any
126-
) -> typing.Optional[EvaluationContext]:
126+
) -> EvaluationContext | None:
127127
"""
128128
Try and run a single hook and catch any exception thrown. This is used in the
129129
after all and error hooks since any error thrown at this point needs to be caught.
@@ -135,7 +135,7 @@ def _execute_hook_checked(
135135
"""
136136
try:
137137
return typing.cast(
138-
"typing.Optional[EvaluationContext]",
138+
"EvaluationContext | None",
139139
getattr(hook, hook_method.value)(**kwargs),
140140
)
141141
except Exception: # pragma: no cover

0 commit comments

Comments
 (0)