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:
Anton Grübel 2024-01-06 18:25:44 +01:00 committed by GitHub
parent 49aae786fb
commit a853b85514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 30 deletions

View File

@ -314,7 +314,7 @@ class OpenFeatureClient:
) )
# Catch any type of exception here since the user can provide any exception # Catch any type of exception here since the user can provide any exception
# in the error hooks # 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_hooks(flag_type, hook_context, err, reversed_merged_hooks, hook_hints)
error_message = getattr(err, "error_message", str(err)) error_message = getattr(err, "error_message", str(err))

View File

@ -31,13 +31,13 @@ class Reason(StrEnum):
FlagMetadata = typing.Mapping[str, typing.Any] FlagMetadata = typing.Mapping[str, typing.Any]
T = typing.TypeVar("T", covariant=True) T_co = typing.TypeVar("T_co", covariant=True)
@dataclass @dataclass
class FlagEvaluationDetails(typing.Generic[T]): class FlagEvaluationDetails(typing.Generic[T_co]):
flag_key: str flag_key: str
value: T value: T_co
variant: typing.Optional[str] = None variant: typing.Optional[str] = None
flag_metadata: FlagMetadata = field(default_factory=dict) flag_metadata: FlagMetadata = field(default_factory=dict)
reason: typing.Optional[Reason] = None reason: typing.Optional[Reason] = None
@ -51,12 +51,12 @@ class FlagEvaluationOptions:
hook_hints: dict = field(default_factory=dict) hook_hints: dict = field(default_factory=dict)
U = typing.TypeVar("U", covariant=True) U_co = typing.TypeVar("U_co", covariant=True)
@dataclass @dataclass
class FlagResolutionDetails(typing.Generic[U]): class FlagResolutionDetails(typing.Generic[U_co]):
value: U value: U_co
error_code: typing.Optional[ErrorCode] = None error_code: typing.Optional[ErrorCode] = None
error_message: typing.Optional[str] = None error_message: typing.Optional[str] = None
reason: typing.Optional[Reason] = None reason: typing.Optional[Reason] = None

View File

@ -26,8 +26,8 @@ class HookContext:
flag_type: FlagType flag_type: FlagType
default_value: typing.Any default_value: typing.Any
evaluation_context: EvaluationContext evaluation_context: EvaluationContext
client_metadata: typing.Optional["ClientMetadata"] = None client_metadata: typing.Optional[ClientMetadata] = None
provider_metadata: typing.Optional["Metadata"] = None provider_metadata: typing.Optional[Metadata] = None
class Hook: class Hook:

View File

@ -116,5 +116,5 @@ def _execute_hook_checked(hook: Hook, hook_method: HookType, **kwargs):
""" """
try: try:
return getattr(hook, hook_method.value)(**kwargs) 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") logging.error(f"Exception when running {hook_method.value} hooks")

View File

@ -17,26 +17,28 @@ class InMemoryMetadata(Metadata):
name: str = "In-Memory Provider" name: str = "In-Memory Provider"
T = typing.TypeVar("T", covariant=True) T_co = typing.TypeVar("T_co", covariant=True)
@dataclass(frozen=True) @dataclass(frozen=True)
class InMemoryFlag(typing.Generic[T]): class InMemoryFlag(typing.Generic[T_co]):
class State(StrEnum): class State(StrEnum):
ENABLED = "ENABLED" ENABLED = "ENABLED"
DISABLED = "DISABLED" DISABLED = "DISABLED"
default_variant: str default_variant: str
variants: typing.Dict[str, T] variants: typing.Dict[str, T_co]
flag_metadata: FlagMetadata = field(default_factory=dict) flag_metadata: FlagMetadata = field(default_factory=dict)
state: State = State.ENABLED state: State = State.ENABLED
context_evaluator: typing.Optional[ context_evaluator: typing.Optional[
typing.Callable[["InMemoryFlag", EvaluationContext], FlagResolutionDetails[T]] typing.Callable[
["InMemoryFlag", EvaluationContext], FlagResolutionDetails[T_co]
]
] = None ] = None
def resolve( def resolve(
self, evaluation_context: typing.Optional[EvaluationContext] self, evaluation_context: typing.Optional[EvaluationContext]
) -> FlagResolutionDetails[T]: ) -> FlagResolutionDetails[T_co]:
if self.context_evaluator: if self.context_evaluator:
return self.context_evaluator( return self.context_evaluator(
self, evaluation_context or EvaluationContext() self, evaluation_context or EvaluationContext()

View File

@ -63,14 +63,6 @@ select = [
] ]
ignore = [ ignore = [
"E501", # the formatter will handle any too long line "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 preview = true

View File

@ -11,7 +11,7 @@ def clear_provider():
in other tests. in other tests.
""" """
yield yield
_provider = None # noqa: F841 _provider = None
@pytest.fixture() @pytest.fixture()

View File

@ -15,7 +15,7 @@ from openfeature.immutable_dict.mapping_proxy_type import MappingProxyType
def test_error_hooks_run_error_method(mock_hook): def test_error_hooks_run_error_method(mock_hook):
# Given # Given
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "") hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
hook_hints = MappingProxyType(dict()) hook_hints = MappingProxyType({})
# When # When
error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], hook_hints) error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], hook_hints)
# Then # Then
@ -29,7 +29,7 @@ def test_error_hooks_run_error_method(mock_hook):
def test_before_hooks_run_before_method(mock_hook): def test_before_hooks_run_before_method(mock_hook):
# Given # Given
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "") hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
hook_hints = MappingProxyType(dict()) hook_hints = MappingProxyType({})
# When # When
before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints) before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints)
# Then # Then
@ -61,7 +61,7 @@ def test_after_hooks_run_after_method(mock_hook):
flag_evaluation_details = FlagEvaluationDetails( flag_evaluation_details = FlagEvaluationDetails(
hook_context.flag_key, "val", "unknown" hook_context.flag_key, "val", "unknown"
) )
hook_hints = MappingProxyType(dict()) hook_hints = MappingProxyType({})
# When # When
after_hooks( after_hooks(
FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], hook_hints 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): def test_finally_after_hooks_run_finally_after_method(mock_hook):
# Given # Given
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "") hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
hook_hints = MappingProxyType(dict()) hook_hints = MappingProxyType({})
# When # When
after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints) after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints)
# Then # Then

View File

@ -1,6 +1,7 @@
import pytest
from numbers import Number from numbers import Number
import pytest
from openfeature.exception import FlagNotFoundError from openfeature.exception import FlagNotFoundError
from openfeature.flag_evaluation import FlagResolutionDetails, Reason from openfeature.flag_evaluation import FlagResolutionDetails, Reason
from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider

View File

@ -53,4 +53,4 @@ def test_evaluation_details_reason_should_be_a_string_when_set():
flag_details.reason = Reason.STATIC flag_details.reason = Reason.STATIC
# Then # Then
assert Reason.STATIC == flag_details.reason assert Reason.STATIC == flag_details.reason # noqa: SIM300