Improve decorator type annotations [core] (#104826)

This commit is contained in:
Marc Mueller 2023-11-30 18:50:31 +01:00 committed by GitHub
parent 46ba62a3c0
commit 2496c275c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 7 deletions

View File

@ -1,7 +1,7 @@
"""API for persistent storage for the frontend."""
from __future__ import annotations
from collections.abc import Callable
from collections.abc import Callable, Coroutine
from functools import wraps
from typing import Any
@ -50,12 +50,19 @@ async def async_user_store(
return store, data[user_id]
def with_store(orig_func: Callable) -> Callable:
def with_store(
orig_func: Callable[
[HomeAssistant, ActiveConnection, dict[str, Any], Store, dict[str, Any]],
Coroutine[Any, Any, None],
],
) -> Callable[
[HomeAssistant, ActiveConnection, dict[str, Any]], Coroutine[Any, Any, None]
]:
"""Decorate function to provide data."""
@wraps(orig_func)
async def with_store_func(
hass: HomeAssistant, connection: ActiveConnection, msg: dict
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Provide user specific data and store to function."""
user_id = connection.user.id

View File

@ -1,6 +1,7 @@
"""Repairs implementation for supervisor integration."""
from __future__ import annotations
from collections.abc import Callable
from collections.abc import Callable, Coroutine
from types import MethodType
from typing import Any
@ -116,7 +117,12 @@ class SupervisorIssueRepairFlow(RepairsFlow):
return self.async_create_entry(data={})
@staticmethod
def _async_step(suggestion: Suggestion) -> Callable:
def _async_step(
suggestion: Suggestion,
) -> Callable[
[SupervisorIssueRepairFlow, dict[str, str] | None],
Coroutine[Any, Any, FlowResult],
]:
"""Generate a step handler for a suggestion."""
async def _async_step(

View File

@ -331,7 +331,12 @@ class SchemaConfigFlowHandler(config_entries.ConfigFlow, ABC):
return cls.options_flow is not None
@staticmethod
def _async_step(step_id: str) -> Callable:
def _async_step(
step_id: str,
) -> Callable[
[SchemaConfigFlowHandler, dict[str, Any] | None],
Coroutine[Any, Any, FlowResult],
]:
"""Generate a step handler."""
async def _async_step(
@ -421,7 +426,12 @@ class SchemaOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry):
setattr(self, "async_setup_preview", async_setup_preview)
@staticmethod
def _async_step(step_id: str) -> Callable:
def _async_step(
step_id: str,
) -> Callable[
[SchemaConfigFlowHandler, dict[str, Any] | None],
Coroutine[Any, Any, FlowResult],
]:
"""Generate a step handler."""
async def _async_step(