feat: specification-0.5.0 (#44)

* feature/spec-0.3.0: Update docs on merging contexts to reflect spec

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

* 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 <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

* feature/spec-0.5.0: Remove returns in exception docstrings
Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>
This commit is contained in:
Andrew Helsby 2022-11-11 15:06:22 +04:00 committed by GitHub
parent 311b8eef53
commit 04a4323310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 27 deletions

View File

@ -1,4 +1,6 @@
from open_feature.flag_evaluation.error_code import ErrorCode import typing
from open_feature.exception.error_code import ErrorCode
class OpenFeatureError(Exception): class OpenFeatureError(Exception):
@ -7,13 +9,14 @@ class OpenFeatureError(Exception):
the more specific exceptions extending this one should be used. the more specific exceptions extending this one should be used.
""" """
def __init__(self, error_message: str = None, error_code: ErrorCode = None): def __init__(
self, error_message: typing.Optional[str] = None, error_code: ErrorCode = None
):
""" """
Constructor for the generic OpenFeatureError. Constructor for the generic OpenFeatureError.
@param error_message: a string message representing why the error has been @param error_message: an optional string message representing why the
raised error has been raised
@param error_code: the ErrorCode string enum value for the type of error @param error_code: the ErrorCode string enum value for the type of error
@return: the generic OpenFeatureError exception
""" """
self.error_message = error_message self.error_message = error_message
self.error_code = error_code self.error_code = error_code
@ -25,13 +28,12 @@ class FlagNotFoundError(OpenFeatureError):
key provided by the user. key provided by the user.
""" """
def __init__(self, error_message: str = None): def __init__(self, error_message: typing.Optional[str] = None):
""" """
Constructor for the FlagNotFoundError. The error code for Constructor for the FlagNotFoundError. The error code for
this type of exception is ErrorCode.FLAG_NOT_FOUND. this type of exception is ErrorCode.FLAG_NOT_FOUND.
@param error_message: a string message representing why the error has been @param error_message: an optional string message representing
raised why the error has been raised
@return: the generic FlagNotFoundError exception
""" """
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND) super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)
@ -42,13 +44,12 @@ class GeneralError(OpenFeatureError):
feature python sdk. feature python sdk.
""" """
def __init__(self, error_message: str = None): def __init__(self, error_message: typing.Optional[str] = None):
""" """
Constructor for the GeneralError. The error code for this type of exception Constructor for the GeneralError. The error code for this type of exception
is ErrorCode.GENERAL. is ErrorCode.GENERAL.
@param error_message: a string message representing why the error has been @param error_message: an optional string message representing why the error
raised has been raised
@return: the generic GeneralError exception
""" """
super().__init__(error_message, ErrorCode.GENERAL) super().__init__(error_message, ErrorCode.GENERAL)
@ -59,13 +60,12 @@ class ParseError(OpenFeatureError):
be parsed into a FlagEvaluationDetails object. be parsed into a FlagEvaluationDetails object.
""" """
def __init__(self, error_message: str = None): def __init__(self, error_message: typing.Optional[str] = None):
""" """
Constructor for the ParseError. The error code for this type of exception Constructor for the ParseError. The error code for this type of exception
is ErrorCode.PARSE_ERROR. is ErrorCode.PARSE_ERROR.
@param error_message: a string message representing why the error has been @param error_message: an optional string message representing why the
raised error has been raised
@return: the generic ParseError exception
""" """
super().__init__(error_message, ErrorCode.PARSE_ERROR) super().__init__(error_message, ErrorCode.PARSE_ERROR)
@ -76,13 +76,12 @@ class TypeMismatchError(OpenFeatureError):
not match the type requested by the user. not match the type requested by the user.
""" """
def __init__(self, error_message: str = None): def __init__(self, error_message: typing.Optional[str] = None):
""" """
Constructor for the TypeMismatchError. The error code for this type of Constructor for the TypeMismatchError. The error code for this type of
exception is ErrorCode.TYPE_MISMATCH. exception is ErrorCode.TYPE_MISMATCH.
@param error_message: a string message representing why the error has been @param error_message: an optional string message representing why the
raised error has been raised
@return: the generic TypeMismatchError exception
""" """
super().__init__(error_message, ErrorCode.TYPE_MISMATCH) super().__init__(error_message, ErrorCode.TYPE_MISMATCH)

View File

@ -1,7 +1,7 @@
import typing import typing
from dataclasses import dataclass from dataclasses import dataclass
from open_feature.flag_evaluation.error_code import ErrorCode from open_feature.exception.error_code import ErrorCode
from open_feature.flag_evaluation.reason import Reason from open_feature.flag_evaluation.reason import Reason
@ -12,4 +12,4 @@ class FlagEvaluationDetails:
variant: str = None variant: str = None
reason: Reason = None reason: Reason = None
error_code: ErrorCode = None error_code: ErrorCode = None
error_message: str = None error_message: typing.Optional[str] = None

View File

@ -2,12 +2,12 @@ import logging
import typing import typing
from open_feature.evaluation_context.evaluation_context import EvaluationContext from open_feature.evaluation_context.evaluation_context import EvaluationContext
from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import ( from open_feature.exception.exceptions import (
GeneralError, GeneralError,
OpenFeatureError, OpenFeatureError,
TypeMismatchError, TypeMismatchError,
) )
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.flag_evaluation.flag_evaluation_details import FlagEvaluationDetails from open_feature.flag_evaluation.flag_evaluation_details import FlagEvaluationDetails
from open_feature.flag_evaluation.flag_evaluation_options import FlagEvaluationOptions from open_feature.flag_evaluation.flag_evaluation_options import FlagEvaluationOptions
from open_feature.flag_evaluation.flag_type import FlagType from open_feature.flag_evaluation.flag_type import FlagType
@ -248,6 +248,7 @@ class OpenFeatureClient:
# https://github.com/open-feature/spec/blob/main/specification/sections/03-evaluation-context.md # https://github.com/open-feature/spec/blob/main/specification/sections/03-evaluation-context.md
# Any resulting evaluation context from a before hook will overwrite # Any resulting evaluation context from a before hook will overwrite
# duplicate fields defined globally, on the client, or in the invocation. # duplicate fields defined globally, on the client, or in the invocation.
# Requirement 3.2.2, 4.3.4: API.context->client.context->invocation.context
invocation_context = before_hooks( invocation_context = before_hooks(
flag_type, hook_context, merged_hooks, None flag_type, hook_context, merged_hooks, None
) )

View File

@ -1,7 +1,7 @@
import pytest import pytest
from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import GeneralError from open_feature.exception.exceptions import GeneralError
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.open_feature_api import get_client, get_provider, set_provider from open_feature.open_feature_api import get_client, get_provider, set_provider
from open_feature.provider.no_op_provider import NoOpProvider from open_feature.provider.no_op_provider import NoOpProvider

View File

@ -2,8 +2,8 @@ from unittest.mock import MagicMock
import pytest import pytest
from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import OpenFeatureError from open_feature.exception.exceptions import OpenFeatureError
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.flag_evaluation.reason import Reason from open_feature.flag_evaluation.reason import Reason
from open_feature.hooks.hook import Hook from open_feature.hooks.hook import Hook

View File

@ -1,8 +1,8 @@
import pytest import pytest
from open_feature.evaluation_context.evaluation_context import EvaluationContext from open_feature.evaluation_context.evaluation_context import EvaluationContext
from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import GeneralError from open_feature.exception.exceptions import GeneralError
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.open_feature_evaluation_context import ( from open_feature.open_feature_evaluation_context import (
api_evaluation_context, api_evaluation_context,
set_api_evaluation_context, set_api_evaluation_context,