Skip to content

Commit 04a4323

Browse files
authored
feat: specification-0.5.0 (#44)
* feature/spec-0.3.0: Update docs on merging contexts to reflect spec Signed-off-by: Andrew Helsby <[email protected]> * feature/spec-0.5.0: Ensure error message is optional and error code required when an error has been found Signed-off-by: Andrew Helsby <[email protected]> Signed-off-by: Andrew Helsby <[email protected]> * feature/spec-0.5.0: Remove returns in exception docstrings Signed-off-by: Andrew Helsby <[email protected]> Signed-off-by: Andrew Helsby <[email protected]> Signed-off-by: Andrew Helsby <[email protected]>
1 parent 311b8ee commit 04a4323

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed
File renamed without changes.

open_feature/exception/exceptions.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from open_feature.flag_evaluation.error_code import ErrorCode
1+
import typing
2+
3+
from open_feature.exception.error_code import ErrorCode
24

35

46
class OpenFeatureError(Exception):
@@ -7,13 +9,14 @@ class OpenFeatureError(Exception):
79
the more specific exceptions extending this one should be used.
810
"""
911

10-
def __init__(self, error_message: str = None, error_code: ErrorCode = None):
12+
def __init__(
13+
self, error_message: typing.Optional[str] = None, error_code: ErrorCode = None
14+
):
1115
"""
1216
Constructor for the generic OpenFeatureError.
13-
@param error_message: a string message representing why the error has been
14-
raised
17+
@param error_message: an optional string message representing why the
18+
error has been raised
1519
@param error_code: the ErrorCode string enum value for the type of error
16-
@return: the generic OpenFeatureError exception
1720
"""
1821
self.error_message = error_message
1922
self.error_code = error_code
@@ -25,13 +28,12 @@ class FlagNotFoundError(OpenFeatureError):
2528
key provided by the user.
2629
"""
2730

28-
def __init__(self, error_message: str = None):
31+
def __init__(self, error_message: typing.Optional[str] = None):
2932
"""
3033
Constructor for the FlagNotFoundError. The error code for
3134
this type of exception is ErrorCode.FLAG_NOT_FOUND.
32-
@param error_message: a string message representing why the error has been
33-
raised
34-
@return: the generic FlagNotFoundError exception
35+
@param error_message: an optional string message representing
36+
why the error has been raised
3537
"""
3638
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)
3739

@@ -42,13 +44,12 @@ class GeneralError(OpenFeatureError):
4244
feature python sdk.
4345
"""
4446

45-
def __init__(self, error_message: str = None):
47+
def __init__(self, error_message: typing.Optional[str] = None):
4648
"""
4749
Constructor for the GeneralError. The error code for this type of exception
4850
is ErrorCode.GENERAL.
49-
@param error_message: a string message representing why the error has been
50-
raised
51-
@return: the generic GeneralError exception
51+
@param error_message: an optional string message representing why the error
52+
has been raised
5253
"""
5354
super().__init__(error_message, ErrorCode.GENERAL)
5455

@@ -59,13 +60,12 @@ class ParseError(OpenFeatureError):
5960
be parsed into a FlagEvaluationDetails object.
6061
"""
6162

62-
def __init__(self, error_message: str = None):
63+
def __init__(self, error_message: typing.Optional[str] = None):
6364
"""
6465
Constructor for the ParseError. The error code for this type of exception
6566
is ErrorCode.PARSE_ERROR.
66-
@param error_message: a string message representing why the error has been
67-
raised
68-
@return: the generic ParseError exception
67+
@param error_message: an optional string message representing why the
68+
error has been raised
6969
"""
7070
super().__init__(error_message, ErrorCode.PARSE_ERROR)
7171

@@ -76,13 +76,12 @@ class TypeMismatchError(OpenFeatureError):
7676
not match the type requested by the user.
7777
"""
7878

79-
def __init__(self, error_message: str = None):
79+
def __init__(self, error_message: typing.Optional[str] = None):
8080
"""
8181
Constructor for the TypeMismatchError. The error code for this type of
8282
exception is ErrorCode.TYPE_MISMATCH.
83-
@param error_message: a string message representing why the error has been
84-
raised
85-
@return: the generic TypeMismatchError exception
83+
@param error_message: an optional string message representing why the
84+
error has been raised
8685
"""
8786
super().__init__(error_message, ErrorCode.TYPE_MISMATCH)
8887

open_feature/flag_evaluation/flag_evaluation_details.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typing
22
from dataclasses import dataclass
33

4-
from open_feature.flag_evaluation.error_code import ErrorCode
4+
from open_feature.exception.error_code import ErrorCode
55
from open_feature.flag_evaluation.reason import Reason
66

77

@@ -12,4 +12,4 @@ class FlagEvaluationDetails:
1212
variant: str = None
1313
reason: Reason = None
1414
error_code: ErrorCode = None
15-
error_message: str = None
15+
error_message: typing.Optional[str] = None

open_feature/open_feature_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import typing
33

44
from open_feature.evaluation_context.evaluation_context import EvaluationContext
5+
from open_feature.exception.error_code import ErrorCode
56
from open_feature.exception.exceptions import (
67
GeneralError,
78
OpenFeatureError,
89
TypeMismatchError,
910
)
10-
from open_feature.flag_evaluation.error_code import ErrorCode
1111
from open_feature.flag_evaluation.flag_evaluation_details import FlagEvaluationDetails
1212
from open_feature.flag_evaluation.flag_evaluation_options import FlagEvaluationOptions
1313
from open_feature.flag_evaluation.flag_type import FlagType
@@ -248,6 +248,7 @@ def evaluate_flag_details(
248248
# https://github.com/open-feature/spec/blob/main/specification/sections/03-evaluation-context.md
249249
# Any resulting evaluation context from a before hook will overwrite
250250
# duplicate fields defined globally, on the client, or in the invocation.
251+
# Requirement 3.2.2, 4.3.4: API.context->client.context->invocation.context
251252
invocation_context = before_hooks(
252253
flag_type, hook_context, merged_hooks, None
253254
)

tests/test_open_feature_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

3+
from open_feature.exception.error_code import ErrorCode
34
from open_feature.exception.exceptions import GeneralError
4-
from open_feature.flag_evaluation.error_code import ErrorCode
55
from open_feature.open_feature_api import get_client, get_provider, set_provider
66
from open_feature.provider.no_op_provider import NoOpProvider
77

tests/test_open_feature_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44

5+
from open_feature.exception.error_code import ErrorCode
56
from open_feature.exception.exceptions import OpenFeatureError
6-
from open_feature.flag_evaluation.error_code import ErrorCode
77
from open_feature.flag_evaluation.reason import Reason
88
from open_feature.hooks.hook import Hook
99

tests/test_open_feature_evaluation_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
22

33
from open_feature.evaluation_context.evaluation_context import EvaluationContext
4+
from open_feature.exception.error_code import ErrorCode
45
from open_feature.exception.exceptions import GeneralError
5-
from open_feature.flag_evaluation.error_code import ErrorCode
66
from open_feature.open_feature_evaluation_context import (
77
api_evaluation_context,
88
set_api_evaluation_context,

0 commit comments

Comments
 (0)