1
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:
Marc Mueller 2022-02-14 18:23:12 +01:00 committed by GitHub
parent b6a3b012bb
commit 3b3e12aaa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ from __future__ import annotations
import asyncio
from collections import ChainMap
from collections.abc import Mapping
import logging
from typing import Any
@ -134,7 +135,7 @@ def _build_resources(
translation_strings: dict[str, dict[str, Any]],
components: set[str],
category: str,
) -> dict[str, dict[str, Any]]:
) -> dict[str, dict[str, Any] | str]:
"""Build the resources response for the given components."""
# Build response
return {
@ -251,6 +252,7 @@ class _TranslationCache:
translation_strings: dict[str, dict[str, Any]],
) -> None:
"""Extract resources into the cache."""
resource: dict[str, Any] | str
cached = self.cache.setdefault(language, {})
categories: set[str] = set()
for resource in translation_strings.values():
@ -260,7 +262,8 @@ class _TranslationCache:
resource_func = (
_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():
category_cache: dict[str, Any] = cached.setdefault(