chore: remove excluded ruff rules and fix issues (#254)
remove excluded ruff rules and fix issues Signed-off-by: gruebel <anton.gruebel@gmail.com>
This commit is contained in:
parent
49aae786fb
commit
a853b85514
|
|
@ -314,7 +314,7 @@ class OpenFeatureClient:
|
|||
)
|
||||
# Catch any type of exception here since the user can provide any exception
|
||||
# in the error hooks
|
||||
except Exception as err: # noqa
|
||||
except Exception as err: # pragma: no cover
|
||||
error_hooks(flag_type, hook_context, err, reversed_merged_hooks, hook_hints)
|
||||
|
||||
error_message = getattr(err, "error_message", str(err))
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ class Reason(StrEnum):
|
|||
|
||||
FlagMetadata = typing.Mapping[str, typing.Any]
|
||||
|
||||
T = typing.TypeVar("T", covariant=True)
|
||||
T_co = typing.TypeVar("T_co", covariant=True)
|
||||
|
||||
|
||||
@dataclass
|
||||
class FlagEvaluationDetails(typing.Generic[T]):
|
||||
class FlagEvaluationDetails(typing.Generic[T_co]):
|
||||
flag_key: str
|
||||
value: T
|
||||
value: T_co
|
||||
variant: typing.Optional[str] = None
|
||||
flag_metadata: FlagMetadata = field(default_factory=dict)
|
||||
reason: typing.Optional[Reason] = None
|
||||
|
|
@ -51,12 +51,12 @@ class FlagEvaluationOptions:
|
|||
hook_hints: dict = field(default_factory=dict)
|
||||
|
||||
|
||||
U = typing.TypeVar("U", covariant=True)
|
||||
U_co = typing.TypeVar("U_co", covariant=True)
|
||||
|
||||
|
||||
@dataclass
|
||||
class FlagResolutionDetails(typing.Generic[U]):
|
||||
value: U
|
||||
class FlagResolutionDetails(typing.Generic[U_co]):
|
||||
value: U_co
|
||||
error_code: typing.Optional[ErrorCode] = None
|
||||
error_message: typing.Optional[str] = None
|
||||
reason: typing.Optional[Reason] = None
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ class HookContext:
|
|||
flag_type: FlagType
|
||||
default_value: typing.Any
|
||||
evaluation_context: EvaluationContext
|
||||
client_metadata: typing.Optional["ClientMetadata"] = None
|
||||
provider_metadata: typing.Optional["Metadata"] = None
|
||||
client_metadata: typing.Optional[ClientMetadata] = None
|
||||
provider_metadata: typing.Optional[Metadata] = None
|
||||
|
||||
|
||||
class Hook:
|
||||
|
|
|
|||
|
|
@ -116,5 +116,5 @@ def _execute_hook_checked(hook: Hook, hook_method: HookType, **kwargs):
|
|||
"""
|
||||
try:
|
||||
return getattr(hook, hook_method.value)(**kwargs)
|
||||
except Exception: # noqa
|
||||
except Exception: # pragma: no cover
|
||||
logging.error(f"Exception when running {hook_method.value} hooks")
|
||||
|
|
|
|||
|
|
@ -17,26 +17,28 @@ class InMemoryMetadata(Metadata):
|
|||
name: str = "In-Memory Provider"
|
||||
|
||||
|
||||
T = typing.TypeVar("T", covariant=True)
|
||||
T_co = typing.TypeVar("T_co", covariant=True)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class InMemoryFlag(typing.Generic[T]):
|
||||
class InMemoryFlag(typing.Generic[T_co]):
|
||||
class State(StrEnum):
|
||||
ENABLED = "ENABLED"
|
||||
DISABLED = "DISABLED"
|
||||
|
||||
default_variant: str
|
||||
variants: typing.Dict[str, T]
|
||||
variants: typing.Dict[str, T_co]
|
||||
flag_metadata: FlagMetadata = field(default_factory=dict)
|
||||
state: State = State.ENABLED
|
||||
context_evaluator: typing.Optional[
|
||||
typing.Callable[["InMemoryFlag", EvaluationContext], FlagResolutionDetails[T]]
|
||||
typing.Callable[
|
||||
["InMemoryFlag", EvaluationContext], FlagResolutionDetails[T_co]
|
||||
]
|
||||
] = None
|
||||
|
||||
def resolve(
|
||||
self, evaluation_context: typing.Optional[EvaluationContext]
|
||||
) -> FlagResolutionDetails[T]:
|
||||
) -> FlagResolutionDetails[T_co]:
|
||||
if self.context_evaluator:
|
||||
return self.context_evaluator(
|
||||
self, evaluation_context or EvaluationContext()
|
||||
|
|
|
|||
|
|
@ -63,14 +63,6 @@ select = [
|
|||
]
|
||||
ignore = [
|
||||
"E501", # the formatter will handle any too long line
|
||||
# all following rules will be removed in the next PR
|
||||
"PGH004",
|
||||
"RUF100",
|
||||
"PLC0105",
|
||||
"UP037",
|
||||
"C408",
|
||||
"I001",
|
||||
"SIM300",
|
||||
]
|
||||
preview = true
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ def clear_provider():
|
|||
in other tests.
|
||||
"""
|
||||
yield
|
||||
_provider = None # noqa: F841
|
||||
_provider = None
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from openfeature.immutable_dict.mapping_proxy_type import MappingProxyType
|
|||
def test_error_hooks_run_error_method(mock_hook):
|
||||
# Given
|
||||
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
|
||||
hook_hints = MappingProxyType(dict())
|
||||
hook_hints = MappingProxyType({})
|
||||
# When
|
||||
error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], hook_hints)
|
||||
# Then
|
||||
|
|
@ -29,7 +29,7 @@ def test_error_hooks_run_error_method(mock_hook):
|
|||
def test_before_hooks_run_before_method(mock_hook):
|
||||
# Given
|
||||
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
|
||||
hook_hints = MappingProxyType(dict())
|
||||
hook_hints = MappingProxyType({})
|
||||
# When
|
||||
before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints)
|
||||
# Then
|
||||
|
|
@ -61,7 +61,7 @@ def test_after_hooks_run_after_method(mock_hook):
|
|||
flag_evaluation_details = FlagEvaluationDetails(
|
||||
hook_context.flag_key, "val", "unknown"
|
||||
)
|
||||
hook_hints = MappingProxyType(dict())
|
||||
hook_hints = MappingProxyType({})
|
||||
# When
|
||||
after_hooks(
|
||||
FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], hook_hints
|
||||
|
|
@ -77,7 +77,7 @@ def test_after_hooks_run_after_method(mock_hook):
|
|||
def test_finally_after_hooks_run_finally_after_method(mock_hook):
|
||||
# Given
|
||||
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
|
||||
hook_hints = MappingProxyType(dict())
|
||||
hook_hints = MappingProxyType({})
|
||||
# When
|
||||
after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints)
|
||||
# Then
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
from numbers import Number
|
||||
|
||||
import pytest
|
||||
|
||||
from openfeature.exception import FlagNotFoundError
|
||||
from openfeature.flag_evaluation import FlagResolutionDetails, Reason
|
||||
from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider
|
||||
|
|
|
|||
|
|
@ -53,4 +53,4 @@ def test_evaluation_details_reason_should_be_a_string_when_set():
|
|||
flag_details.reason = Reason.STATIC
|
||||
|
||||
# Then
|
||||
assert Reason.STATIC == flag_details.reason
|
||||
assert Reason.STATIC == flag_details.reason # noqa: SIM300
|
||||
|
|
|
|||
Loading…
Reference in New Issue