Skip to content

Commit

Permalink
[mypy] Enforcing typing for translations
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley committed May 14, 2020
1 parent cf30e16 commit ad0de37
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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
8 changes: 4 additions & 4 deletions superset/translations/utils.py
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ad0de37

Please sign in to comment.