Skip to content

Commit

Permalink
remove excluded ruff rules and fix issues
Browse files Browse the repository at this point in the history
Signed-off-by: gruebel <[email protected]>
  • Loading branch information
gruebel authored and federicobond committed Jan 6, 2024
1 parent 49aae78 commit f40a6aa
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion openfeature/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def evaluate_flag_details(
)
# 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))
Expand Down
12 changes: 6 additions & 6 deletions openfeature/flag_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions openfeature/hook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion openfeature/hook/hook_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
12 changes: 7 additions & 5 deletions openfeature/provider/in_memory_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def clear_provider():
in other tests.
"""
yield
_provider = None # noqa: F841
_provider = None


@pytest.fixture()
Expand Down
8 changes: 4 additions & 4 deletions tests/hook/test_hook_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/provider/test_in_memory_provider.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flag_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f40a6aa

Please sign in to comment.