Skip to content

Commit

Permalink
Add docblocks to feature flag classes.
Browse files Browse the repository at this point in the history
Related #92
  • Loading branch information
aholmes committed Aug 7, 2024
1 parent 0daebfe commit 3d52569
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/platform/BL_Python/platform/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from BL_Python.programming.config import AbstractConfig
from pydantic import BaseModel


class IdentityRoleConfig(BaseModel):
default: str


class IdentityConfig(BaseModel, AbstractConfig):
role: IdentityRoleConfig | None = None


class Config(BaseModel, AbstractConfig):
identity: IdentityConfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ def _notify_disabled(self, name: str):
@override
def set_feature_is_enabled(self, name: str, is_enabled: bool) -> None:
"""
Enables or disables a feature flag in the in-memory dictionary of feature flags.
Enables or disables a feature flag in the in-memory dictionary of feature flags.
Subclasses should call this method to validate parameters and cache values.
Subclasses should call this method to validate parameters and cache values.
name: The feature flag to check.
is_enabled: Whether the feature flag is to be enabled or disabled.
:param str name: The feature flag to check.
:param bool is_enabled: Whether the feature flag is to be enabled or disabled.
"""
if type(name) != str:
raise TypeError("`name` must be a string.")
Expand All @@ -62,11 +61,11 @@ def feature_is_enabled(
Subclasses should call this method to validate parameters and use cached values.
name: The feature flag to check.
default: If the feature flag is not in the in-memory dictionary of flags,
:param str name: The feature flag to check.
:param bool | None default: If the feature flag is not in the in-memory dictionary of flags,
this is the default value to return. The default parameter value
when not specified is `False`.
:return bool | None: If `True`, the feature is enabled. If `False` or `None`, the feature is disabled.
"""
if type(name) != str:
raise TypeError("`name` must be a string.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,41 @@ class FeatureFlagRouter(ABC):

@abstractmethod
def _notify_enabled(self, name: str) -> None:
""" """
"""
Override to provide a method to be used to notify when a feature is enabled.
Implementation of when and whether this is called is the responsibility of subclasses.
This is never called by default.
:param str name: The name of the feature flag.
"""

@abstractmethod
def _notify_disabled(self, name: str) -> None:
""" """
"""
Override to provide a method to be used to notify when a feature is disabled.
Implementation of when and whether this is called is the responsibility of subclasses.
This is never called by default.
:param str name: The name of the feature flag.
"""

@abstractmethod
def set_feature_is_enabled(self, name: str, is_enabled: bool) -> None:
""" """
"""
Enable or disable a feature flag.
:param str name: The name of the feature flag.
:param bool is_enabled: If `True`, the feature is enabled. If `False`, the feature is disabled.
"""

@abstractmethod
def feature_is_enabled(
self, name: str, default: bool | None = False
) -> bool | None:
""" """
"""
Determine whether a feature flag is enabled or disabled.
:param str name: The name of the feature flag.
:param bool | None default: A default value to return for cases where a feature flag may not exist. Defaults to False.
:return bool | None: If `True`, the feature is enabled. If `False` or `None`, the feature is disabled.
"""

0 comments on commit 3d52569

Please sign in to comment.