diff --git a/openfeature/client.py b/openfeature/client.py index 8f06edd2..cc29897f 100644 --- a/openfeature/client.py +++ b/openfeature/client.py @@ -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)) diff --git a/openfeature/flag_evaluation.py b/openfeature/flag_evaluation.py index b3a066d1..251351da 100644 --- a/openfeature/flag_evaluation.py +++ b/openfeature/flag_evaluation.py @@ -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 diff --git a/openfeature/hook/__init__.py b/openfeature/hook/__init__.py index f0923ea0..590843bf 100644 --- a/openfeature/hook/__init__.py +++ b/openfeature/hook/__init__.py @@ -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: diff --git a/openfeature/hook/hook_support.py b/openfeature/hook/hook_support.py index 003fb1a2..e1432c80 100644 --- a/openfeature/hook/hook_support.py +++ b/openfeature/hook/hook_support.py @@ -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") diff --git a/openfeature/provider/in_memory_provider.py b/openfeature/provider/in_memory_provider.py index 1f526bca..2495d2dc 100644 --- a/openfeature/provider/in_memory_provider.py +++ b/openfeature/provider/in_memory_provider.py @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 8502b2af..3679563d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 6cc940ca..b97e5478 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,7 +11,7 @@ def clear_provider(): in other tests. """ yield - _provider = None # noqa: F841 + _provider = None @pytest.fixture() diff --git a/tests/hook/test_hook_support.py b/tests/hook/test_hook_support.py index c88d237d..ede4a328 100644 --- a/tests/hook/test_hook_support.py +++ b/tests/hook/test_hook_support.py @@ -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 @@ -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 diff --git a/tests/provider/test_in_memory_provider.py b/tests/provider/test_in_memory_provider.py index 505f5ec6..66d5239e 100644 --- a/tests/provider/test_in_memory_provider.py +++ b/tests/provider/test_in_memory_provider.py @@ -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 diff --git a/tests/test_flag_evaluation.py b/tests/test_flag_evaluation.py index 4241ad95..ec6d9411 100644 --- a/tests/test_flag_evaluation.py +++ b/tests/test_flag_evaluation.py @@ -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