1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Store runtime data inside ConfigEntry (#115669)

This commit is contained in:
Marc Mueller
2024-04-30 11:29:43 +02:00
committed by GitHub
parent 258e20bfc4
commit dace9b32de
7 changed files with 118 additions and 23 deletions

View File

@@ -23,6 +23,10 @@ _COMMON_ARGUMENTS: dict[str, list[str]] = {
"hass": ["HomeAssistant", "HomeAssistant | None"]
}
_PLATFORMS: set[str] = {platform.value for platform in Platform}
_KNOWN_GENERIC_TYPES: set[str] = {
"ConfigEntry",
}
_KNOWN_GENERIC_TYPES_TUPLE = tuple(_KNOWN_GENERIC_TYPES)
class _Special(Enum):
@@ -2977,6 +2981,16 @@ def _is_valid_type(
):
return True
# Allow subscripts or type aliases for generic types
if (
isinstance(node, nodes.Subscript)
and isinstance(node.value, nodes.Name)
and node.value.name in _KNOWN_GENERIC_TYPES
or isinstance(node, nodes.Name)
and node.name.endswith(_KNOWN_GENERIC_TYPES_TUPLE)
):
return True
# Name occurs when a namespace is not used, eg. "HomeAssistant"
if isinstance(node, nodes.Name) and node.name == expected_type:
return True