mirror of
https://github.com/home-assistant/core
synced 2024-10-04 07:58:43 +02:00
Fix translation
typing (#66516)
This commit is contained in:
parent
b6a3b012bb
commit
3b3e12aaa2
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import ChainMap
|
from collections import ChainMap
|
||||||
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -134,7 +135,7 @@ def _build_resources(
|
|||||||
translation_strings: dict[str, dict[str, Any]],
|
translation_strings: dict[str, dict[str, Any]],
|
||||||
components: set[str],
|
components: set[str],
|
||||||
category: str,
|
category: str,
|
||||||
) -> dict[str, dict[str, Any]]:
|
) -> dict[str, dict[str, Any] | str]:
|
||||||
"""Build the resources response for the given components."""
|
"""Build the resources response for the given components."""
|
||||||
# Build response
|
# Build response
|
||||||
return {
|
return {
|
||||||
@ -251,6 +252,7 @@ class _TranslationCache:
|
|||||||
translation_strings: dict[str, dict[str, Any]],
|
translation_strings: dict[str, dict[str, Any]],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Extract resources into the cache."""
|
"""Extract resources into the cache."""
|
||||||
|
resource: dict[str, Any] | str
|
||||||
cached = self.cache.setdefault(language, {})
|
cached = self.cache.setdefault(language, {})
|
||||||
categories: set[str] = set()
|
categories: set[str] = set()
|
||||||
for resource in translation_strings.values():
|
for resource in translation_strings.values():
|
||||||
@ -260,7 +262,8 @@ class _TranslationCache:
|
|||||||
resource_func = (
|
resource_func = (
|
||||||
_merge_resources if category == "state" else _build_resources
|
_merge_resources if category == "state" else _build_resources
|
||||||
)
|
)
|
||||||
new_resources = resource_func(translation_strings, components, category)
|
new_resources: Mapping[str, dict[str, Any] | str]
|
||||||
|
new_resources = resource_func(translation_strings, components, category) # type: ignore[assignment]
|
||||||
|
|
||||||
for component, resource in new_resources.items():
|
for component, resource in new_resources.items():
|
||||||
category_cache: dict[str, Any] = cached.setdefault(
|
category_cache: dict[str, Any] = cached.setdefault(
|
||||||
|
Loading…
Reference in New Issue
Block a user