From ad0de37c79a63e7c22219474a80f619b52a8a246 Mon Sep 17 00:00:00 2001 From: John Bodley Date: Wed, 13 May 2020 14:54:10 -0700 Subject: [PATCH] [mypy] Enforcing typing for translations --- setup.cfg | 2 +- superset/translations/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index e5717964201c..87d49f1e343e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -53,7 +53,7 @@ order_by_type = false ignore_missing_imports = true no_implicit_optional = true -[mypy-superset.bin.*,superset.charts.*,superset.datasets.*,superset.dashboards.*,superset.commands.*,superset.common.*,superset.dao.*,superset.db_engine_specs.*,superset.db_engines.*,superset.examples.*,superset.migrations.*,superset.queries.*,superset.security.*,superset.sql_validators.*,superset.tasks.*] +[mypy-superset.bin.*,superset.charts.*,superset.datasets.*,superset.dashboards.*,superset.commands.*,superset.common.*,superset.dao.*,superset.db_engine_specs.*,superset.db_engines.*,superset.examples.*,superset.migrations.*,superset.queries.*,superset.security.*,superset.sql_validators.*,superset.tasks.*,superset.translations.*] check_untyped_defs = true disallow_untyped_calls = true disallow_untyped_defs = true diff --git a/superset/translations/utils.py b/superset/translations/utils.py index bfb12bbe34c1..25a698f0e111 100644 --- a/superset/translations/utils.py +++ b/superset/translations/utils.py @@ -16,15 +16,15 @@ # under the License. import json import os -from typing import Any, Dict +from typing import Any, Dict, Optional # Global caching for JSON language packs -ALL_LANGUAGE_PACKS: Dict[str, Dict[Any, Any]] = {"en": {}} +ALL_LANGUAGE_PACKS: Dict[str, Dict[str, Any]] = {"en": {}} DIR = os.path.dirname(os.path.abspath(__file__)) -def get_language_pack(locale): +def get_language_pack(locale: str) -> Optional[Dict[str, Any]]: """Get/cache a language pack Returns the langugage pack from cache if it exists, caches otherwise @@ -38,7 +38,7 @@ def get_language_pack(locale): try: with open(filename, encoding="utf8") as f: pack = json.load(f) - ALL_LANGUAGE_PACKS[locale] = pack + ALL_LANGUAGE_PACKS[locale] = pack or {} except Exception: # pylint: disable=broad-except # Assuming english, client side falls back on english pass