From 34ac91c707103fa50e905c54148f09615c610c33 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Tue, 9 Apr 2024 12:15:30 +1000 Subject: [PATCH] fix!: restrict exported names with __all__ (#306) * fix!: restrict exported names with __all__ Signed-off-by: Federico Bond * restrict codecov upload to Python 3.11 Signed-off-by: gruebel * disable codecov ci fail on error Signed-off-by: Michael Beemer --------- Signed-off-by: Federico Bond Signed-off-by: gruebel Signed-off-by: Michael Beemer Co-authored-by: gruebel Co-authored-by: Michael Beemer --- .github/workflows/build.yml | 5 +++-- openfeature/api.py | 15 +++++++++++++++ openfeature/client.py | 5 +++++ openfeature/evaluation_context.py | 2 ++ openfeature/event.py | 2 ++ openfeature/exception.py | 13 +++++++++++++ openfeature/flag_evaluation.py | 10 ++++++++++ openfeature/hook/__init__.py | 2 ++ openfeature/provider/__init__.py | 2 ++ openfeature/provider/provider.py | 2 ++ 10 files changed, 56 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9cb863d6..f78ea064 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,12 +43,13 @@ jobs: - name: Run E2E tests with behave run: hatch run e2e - - name: Upload coverage to Codecov + - if: matrix.python-version == '3.11' + name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: flags: unittests # optional name: coverage # optional - fail_ci_if_error: true # optional (default = false) + fail_ci_if_error: false # optional (default = false) verbose: true # optional (default = false) lint: diff --git a/openfeature/api.py b/openfeature/api.py index cbff4b62..c04d423e 100644 --- a/openfeature/api.py +++ b/openfeature/api.py @@ -13,6 +13,21 @@ from openfeature.provider._registry import provider_registry from openfeature.provider.metadata import Metadata +__all__ = [ + "get_client", + "set_provider", + "clear_providers", + "get_provider_metadata", + "get_evaluation_context", + "set_evaluation_context", + "add_hooks", + "clear_hooks", + "get_hooks", + "shutdown", + "add_handler", + "remove_handler", +] + _evaluation_context = EvaluationContext() _hooks: typing.List[Hook] = [] diff --git a/openfeature/client.py b/openfeature/client.py index c2203ca1..0429911a 100644 --- a/openfeature/client.py +++ b/openfeature/client.py @@ -30,6 +30,11 @@ from openfeature.provider import FeatureProvider, ProviderStatus from openfeature.provider._registry import provider_registry +__all__ = [ + "ClientMetadata", + "OpenFeatureClient", +] + logger = logging.getLogger("openfeature") GetDetailCallable = typing.Union[ diff --git a/openfeature/evaluation_context.py b/openfeature/evaluation_context.py index 829ada63..c3af350c 100644 --- a/openfeature/evaluation_context.py +++ b/openfeature/evaluation_context.py @@ -1,6 +1,8 @@ import typing from dataclasses import dataclass, field +__all__ = ["EvaluationContext"] + @dataclass class EvaluationContext: diff --git a/openfeature/event.py b/openfeature/event.py index 367e5859..5fd64d2d 100644 --- a/openfeature/event.py +++ b/openfeature/event.py @@ -7,6 +7,8 @@ from openfeature.exception import ErrorCode from openfeature.provider import ProviderStatus +__all__ = ["ProviderEvent", "ProviderEventDetails", "EventDetails", "EventHandler"] + class ProviderEvent(Enum): PROVIDER_READY = "PROVIDER_READY" diff --git a/openfeature/exception.py b/openfeature/exception.py index d17c28fb..3ae54a56 100644 --- a/openfeature/exception.py +++ b/openfeature/exception.py @@ -4,6 +4,19 @@ from collections.abc import Mapping from enum import Enum +__all__ = [ + "OpenFeatureError", + "ProviderNotReadyError", + "ProviderFatalError", + "FlagNotFoundError", + "GeneralError", + "ParseError", + "TypeMismatchError", + "TargetingKeyMissingError", + "InvalidContextError", + "ErrorCode", +] + class OpenFeatureError(Exception): """ diff --git a/openfeature/flag_evaluation.py b/openfeature/flag_evaluation.py index 86233ed2..db9cea1b 100644 --- a/openfeature/flag_evaluation.py +++ b/openfeature/flag_evaluation.py @@ -11,6 +11,16 @@ from openfeature.hook import Hook, HookHints +__all__ = [ + "FlagType", + "Reason", + "FlagMetadata", + "FlagEvaluationDetails", + "FlagEvaluationOptions", + "FlagResolutionDetails", +] + + class FlagType(StrEnum): BOOLEAN = "BOOLEAN" STRING = "STRING" diff --git a/openfeature/hook/__init__.py b/openfeature/hook/__init__.py index 8cb1c14c..e1524ad1 100644 --- a/openfeature/hook/__init__.py +++ b/openfeature/hook/__init__.py @@ -12,6 +12,8 @@ from openfeature.client import ClientMetadata from openfeature.provider.metadata import Metadata +__all__ = ["HookType", "HookContext", "HookHints", "Hook"] + class HookType(Enum): BEFORE = "before" diff --git a/openfeature/provider/__init__.py b/openfeature/provider/__init__.py index 30ed103f..77111f29 100644 --- a/openfeature/provider/__init__.py +++ b/openfeature/provider/__init__.py @@ -7,6 +7,8 @@ from .metadata import Metadata +__all__ = ["ProviderStatus", "FeatureProvider", "Metadata"] + class ProviderStatus(Enum): NOT_READY = "NOT_READY" diff --git a/openfeature/provider/provider.py b/openfeature/provider/provider.py index debc1d56..9fc85946 100644 --- a/openfeature/provider/provider.py +++ b/openfeature/provider/provider.py @@ -8,6 +8,8 @@ from openfeature.provider import FeatureProvider from openfeature.provider.metadata import Metadata +__all__ = ["AbstractProvider"] + class AbstractProvider(FeatureProvider): def initialize(self, evaluation_context: EvaluationContext) -> None: