Skip to content

Commit 8691574

Browse files
authored
style: bump ruff target version from 3.9 to 3.10 (#557)
Signed-off-by: Matthew Keeler <[email protected]>
1 parent 04106f5 commit 8691574

File tree

17 files changed

+236
-298
lines changed

17 files changed

+236
-298
lines changed

openfeature/api.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import typing
2-
31
from openfeature import _event_support
42
from openfeature.client import OpenFeatureClient
53
from openfeature.evaluation_context import (
@@ -40,14 +38,12 @@
4038

4139

4240
def get_client(
43-
domain: typing.Optional[str] = None, version: typing.Optional[str] = None
41+
domain: str | None = None, version: str | None = None
4442
) -> OpenFeatureClient:
4543
return OpenFeatureClient(domain=domain, version=version)
4644

4745

48-
def set_provider(
49-
provider: FeatureProvider, domain: typing.Optional[str] = None
50-
) -> None:
46+
def set_provider(provider: FeatureProvider, domain: str | None = None) -> None:
5147
if domain is None:
5248
provider_registry.set_default_provider(provider)
5349
else:
@@ -59,7 +55,7 @@ def clear_providers() -> None:
5955
_event_support.clear()
6056

6157

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

6561

openfeature/client.py

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

openfeature/evaluation_context/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
__all__ = ["EvaluationContext", "get_evaluation_context", "set_evaluation_context"]
1111

1212
# https://openfeature.dev/specification/sections/evaluation-context#requirement-312
13-
EvaluationContextAttribute = typing.Union[
14-
bool,
15-
int,
16-
float,
17-
str,
18-
datetime,
19-
Sequence["EvaluationContextAttribute"],
20-
Mapping[str, "EvaluationContextAttribute"],
21-
]
13+
EvaluationContextAttribute: typing.TypeAlias = (
14+
bool
15+
| int
16+
| float
17+
| str
18+
| datetime
19+
| Sequence["EvaluationContextAttribute"]
20+
| Mapping[str, "EvaluationContextAttribute"]
21+
)
2222

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 & 13 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,23 +18,19 @@ 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(
26-
default_factory=dict
27-
)
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(default_factory=dict)
2825

2926

3027
@dataclass
3128
class EventDetails(ProviderEventDetails):
3229
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(
37-
default_factory=dict
38-
)
30+
flags_changed: list[str] | None = None
31+
message: str | None = None
32+
error_code: ErrorCode | None = None
33+
metadata: dict[str, bool | str | int | float] = field(default_factory=dict)
3934

4035
@classmethod
4136
def from_provider_event_details(

openfeature/exception.py

Lines changed: 9 additions & 12 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
@@ -25,9 +24,7 @@ class OpenFeatureError(Exception):
2524
the more specific exceptions extending this one should be used.
2625
"""
2726

28-
def __init__(
29-
self, error_code: ErrorCode, error_message: typing.Optional[str] = None
30-
):
27+
def __init__(self, error_code: ErrorCode, error_message: str | None = None):
3128
"""
3229
Constructor for the generic OpenFeatureError.
3330
@param error_message: an optional string message representing why the
@@ -43,7 +40,7 @@ class ProviderNotReadyError(OpenFeatureError):
4340
This exception should be raised when the provider is not ready to be used.
4441
"""
4542

46-
def __init__(self, error_message: typing.Optional[str] = None):
43+
def __init__(self, error_message: str | None = None):
4744
"""
4845
Constructor for the ProviderNotReadyError. The error code for this type of
4946
exception is ErrorCode.PROVIDER_NOT_READY.
@@ -58,7 +55,7 @@ class ProviderFatalError(OpenFeatureError):
5855
This exception should be raised when the provider encounters a fatal error.
5956
"""
6057

61-
def __init__(self, error_message: typing.Optional[str] = None):
58+
def __init__(self, error_message: str | None = None):
6259
"""
6360
Constructor for the ProviderFatalError. The error code for this type of
6461
exception is ErrorCode.PROVIDER_FATAL.
@@ -74,7 +71,7 @@ class FlagNotFoundError(OpenFeatureError):
7471
key provided by the user.
7572
"""
7673

77-
def __init__(self, error_message: typing.Optional[str] = None):
74+
def __init__(self, error_message: str | None = None):
7875
"""
7976
Constructor for the FlagNotFoundError. The error code for
8077
this type of exception is ErrorCode.FLAG_NOT_FOUND.
@@ -90,7 +87,7 @@ class GeneralError(OpenFeatureError):
9087
feature python sdk.
9188
"""
9289

93-
def __init__(self, error_message: typing.Optional[str] = None):
90+
def __init__(self, error_message: str | None = None):
9491
"""
9592
Constructor for the GeneralError. The error code for this type of exception
9693
is ErrorCode.GENERAL.
@@ -106,7 +103,7 @@ class ParseError(OpenFeatureError):
106103
be parsed into a FlagEvaluationDetails object.
107104
"""
108105

109-
def __init__(self, error_message: typing.Optional[str] = None):
106+
def __init__(self, error_message: str | None = None):
110107
"""
111108
Constructor for the ParseError. The error code for this type of exception
112109
is ErrorCode.PARSE_ERROR.
@@ -122,7 +119,7 @@ class TypeMismatchError(OpenFeatureError):
122119
not match the type requested by the user.
123120
"""
124121

125-
def __init__(self, error_message: typing.Optional[str] = None):
122+
def __init__(self, error_message: str | None = None):
126123
"""
127124
Constructor for the TypeMismatchError. The error code for this type of
128125
exception is ErrorCode.TYPE_MISMATCH.
@@ -138,7 +135,7 @@ class TargetingKeyMissingError(OpenFeatureError):
138135
but one was not provided in the evaluation context.
139136
"""
140137

141-
def __init__(self, error_message: typing.Optional[str] = None):
138+
def __init__(self, error_message: str | None = None):
142139
"""
143140
Constructor for the TargetingKeyMissingError. The error code for this type of
144141
exception is ErrorCode.TARGETING_KEY_MISSING.
@@ -154,7 +151,7 @@ class InvalidContextError(OpenFeatureError):
154151
requirements.
155152
"""
156153

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

openfeature/flag_evaluation.py

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

4444

45-
FlagMetadata = Mapping[str, typing.Union[bool, int, float, str]]
46-
FlagValueType = typing.Union[
47-
bool,
48-
int,
49-
float,
50-
str,
51-
Sequence["FlagValueType"],
52-
Mapping[str, "FlagValueType"],
53-
]
45+
FlagMetadata = Mapping[str, bool | int | float | str]
46+
FlagValueType: typing.TypeAlias = (
47+
bool | int | float | str | Sequence["FlagValueType"] | Mapping[str, "FlagValueType"]
48+
)
5449

5550
T_co = typing.TypeVar("T_co", covariant=True)
5651

@@ -59,13 +54,13 @@ class Reason(StrEnum):
5954
class FlagEvaluationDetails(typing.Generic[T_co]):
6055
flag_key: str
6156
value: T_co
62-
variant: typing.Optional[str] = None
57+
variant: str | None = None
6358
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
59+
reason: str | Reason | None = None
60+
error_code: ErrorCode | None = None
61+
error_message: str | None = None
6762

68-
def get_exception(self) -> typing.Optional[OpenFeatureError]:
63+
def get_exception(self) -> OpenFeatureError | None:
6964
if self.error_code:
7065
return ErrorCode.to_exception(self.error_code, self.error_message or "")
7166
return None
@@ -83,10 +78,10 @@ class FlagEvaluationOptions:
8378
@dataclass
8479
class FlagResolutionDetails(typing.Generic[U_co]):
8580
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
81+
error_code: ErrorCode | None = None
82+
error_message: str | None = None
83+
reason: str | Reason | None = None
84+
variant: str | None = None
9085
flag_metadata: FlagMetadata = field(default_factory=dict)
9186

9287
def raise_for_error(self) -> None:

openfeature/hook/__init__.py

Lines changed: 13 additions & 13 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
@@ -69,23 +69,23 @@ def __setattr__(self, key: str, value: typing.Any) -> None:
6969

7070

7171
# https://openfeature.dev/specification/sections/hooks/#requirement-421
72-
HookHintValue = typing.Union[
73-
bool,
74-
int,
75-
float,
76-
str,
77-
datetime,
78-
Sequence["HookHintValue"],
79-
Mapping[str, "HookHintValue"],
80-
]
72+
HookHintValue: typing.TypeAlias = (
73+
bool
74+
| int
75+
| float
76+
| str
77+
| datetime
78+
| Sequence["HookHintValue"]
79+
| Mapping[str, "HookHintValue"]
80+
)
8181

8282
HookHints = Mapping[str, HookHintValue]
8383

8484

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)