Improve decorator type annotations (#104821)

This commit is contained in:
Marc Mueller 2023-11-30 18:45:18 +01:00 committed by GitHub
parent 4bc1e5075a
commit d597cfec49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View File

@ -2,9 +2,9 @@
from __future__ import annotations
import asyncio
from collections.abc import Awaitable, Callable
from collections.abc import Awaitable, Callable, Coroutine
from dataclasses import dataclass
from typing import cast
from typing import Any, cast
from aioguardian import Client
from aioguardian.errors import GuardianError
@ -170,7 +170,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@callback
def call_with_data(func: Callable) -> Callable:
def call_with_data(
func: Callable[[ServiceCall, GuardianData], Coroutine[Any, Any, None]]
) -> Callable[[ServiceCall], Coroutine[Any, Any, None]]:
"""Hydrate a service call with the appropriate GuardianData object."""
async def wrapper(call: ServiceCall) -> None:

View File

@ -2,7 +2,7 @@
from __future__ import annotations
import asyncio
from collections.abc import Awaitable, Callable
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from datetime import timedelta
from functools import partial, wraps
@ -326,10 +326,17 @@ async def async_setup_entry( # noqa: C901
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
def call_with_controller(update_programs_and_zones: bool = True) -> Callable:
def call_with_controller(
update_programs_and_zones: bool = True,
) -> Callable[
[Callable[[ServiceCall, Controller], Coroutine[Any, Any, None]]],
Callable[[ServiceCall], Coroutine[Any, Any, None]],
]:
"""Hydrate a service call with the appropriate controller."""
def decorator(func: Callable) -> Callable[..., Awaitable]:
def decorator(
func: Callable[[ServiceCall, Controller], Coroutine[Any, Any, None]]
) -> Callable[[ServiceCall], Coroutine[Any, Any, None]]:
"""Define the decorator."""
@wraps(func)

View File

@ -2,7 +2,7 @@
from __future__ import annotations
import asyncio
from collections.abc import Callable, Iterable
from collections.abc import Callable, Coroutine, Iterable
from datetime import timedelta
from typing import Any, cast
@ -336,7 +336,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@callback
def extract_system(func: Callable) -> Callable:
def extract_system(
func: Callable[[ServiceCall, SystemType], Coroutine[Any, Any, None]]
) -> Callable[[ServiceCall], Coroutine[Any, Any, None]]:
"""Define a decorator to get the correct system for a service call."""
async def wrapper(call: ServiceCall) -> None: