Add first TypeVarTuple annotations (#105379)

This commit is contained in:
Marc Mueller 2023-12-18 00:38:07 +01:00 committed by GitHub
parent 5c503683b7
commit aac02d7b84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -5,11 +5,13 @@ import asyncio
from collections.abc import Callable, Hashable from collections.abc import Callable, Hashable
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
from typing import Any from typing import TypeVarTuple
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
_Ts = TypeVarTuple("_Ts")
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -59,8 +61,8 @@ class KeyedRateLimit:
key: Hashable, key: Hashable,
rate_limit: timedelta | None, rate_limit: timedelta | None,
now: datetime, now: datetime,
action: Callable, action: Callable[[*_Ts], None],
*args: Any, *args: *_Ts,
) -> datetime | None: ) -> datetime | None:
"""Check rate limits and schedule an action if we hit the limit. """Check rate limits and schedule an action if we hit the limit.

View File

@ -10,7 +10,7 @@ import functools
import logging import logging
import threading import threading
from traceback import extract_stack from traceback import extract_stack
from typing import Any, ParamSpec, TypeVar from typing import Any, ParamSpec, TypeVar, TypeVarTuple
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
@ -21,6 +21,7 @@ _SHUTDOWN_RUN_CALLBACK_THREADSAFE = "_shutdown_run_callback_threadsafe"
_T = TypeVar("_T") _T = TypeVar("_T")
_R = TypeVar("_R") _R = TypeVar("_R")
_P = ParamSpec("_P") _P = ParamSpec("_P")
_Ts = TypeVarTuple("_Ts")
def cancelling(task: Future[Any]) -> bool: def cancelling(task: Future[Any]) -> bool:
@ -29,7 +30,7 @@ def cancelling(task: Future[Any]) -> bool:
def run_callback_threadsafe( def run_callback_threadsafe(
loop: AbstractEventLoop, callback: Callable[..., _T], *args: Any loop: AbstractEventLoop, callback: Callable[[*_Ts], _T], *args: *_Ts
) -> concurrent.futures.Future[_T]: ) -> concurrent.futures.Future[_T]:
"""Submit a callback object to a given event loop. """Submit a callback object to a given event loop.