mirror of https://github.com/apache/superset.git
[mypy] Enforcing typing for translations (#9800)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
parent
5ab5457522
commit
53b58edd6f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue