[mypy] Enforcing typing for superset.utils (#9905)

Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
John Bodley
2020-05-27 22:57:30 -07:00
committed by GitHub
parent 54dced1cf6
commit b296a0f250
17 changed files with 194 additions and 148 deletions

View File

@@ -15,25 +15,33 @@
# specific language governing permissions and limitations
# under the License.
from copy import deepcopy
from typing import Any, Dict
from flask import Flask
class FeatureFlagManager:
def __init__(self) -> None:
super().__init__()
self._get_feature_flags_func = None
self._feature_flags = None
self._feature_flags: Dict[str, Any] = {}
def init_app(self, app):
self._get_feature_flags_func = app.config.get("GET_FEATURE_FLAGS_FUNC")
self._feature_flags = app.config.get("DEFAULT_FEATURE_FLAGS") or {}
self._feature_flags.update(app.config.get("FEATURE_FLAGS") or {})
def init_app(self, app: Flask) -> None:
self._get_feature_flags_func = app.config["GET_FEATURE_FLAGS_FUNC"]
self._feature_flags = app.config["DEFAULT_FEATURE_FLAGS"]
self._feature_flags.update(app.config["FEATURE_FLAGS"])
def get_feature_flags(self):
def get_feature_flags(self) -> Dict[str, Any]:
if self._get_feature_flags_func:
return self._get_feature_flags_func(deepcopy(self._feature_flags))
return self._feature_flags
def is_feature_enabled(self, feature) -> bool:
def is_feature_enabled(self, feature: str) -> bool:
"""Utility function for checking whether a feature is turned on"""
return self.get_feature_flags().get(feature)
feature_flags = self.get_feature_flags()
if feature_flags and feature in feature_flags:
return feature_flags[feature]
return False