mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Use PEP 695 for function annotations (3) (#117660)
This commit is contained in:
@ -41,7 +41,6 @@ from typing import (
|
||||
ParamSpec,
|
||||
Self,
|
||||
TypedDict,
|
||||
TypeVarTuple,
|
||||
cast,
|
||||
overload,
|
||||
)
|
||||
@ -131,15 +130,12 @@ FINAL_WRITE_STAGE_SHUTDOWN_TIMEOUT = 60
|
||||
CLOSE_STAGE_SHUTDOWN_TIMEOUT = 30
|
||||
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_R = TypeVar("_R")
|
||||
_R_co = TypeVar("_R_co", covariant=True)
|
||||
_P = ParamSpec("_P")
|
||||
_Ts = TypeVarTuple("_Ts")
|
||||
# Internal; not helpers.typing.UNDEFINED due to circular dependency
|
||||
_UNDEF: dict[Any, Any] = {}
|
||||
_SENTINEL = object()
|
||||
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any])
|
||||
_DataT = TypeVar("_DataT", bound=Mapping[str, Any], default=Mapping[str, Any])
|
||||
type CALLBACK_TYPE = Callable[[], None]
|
||||
|
||||
@ -234,7 +230,7 @@ def validate_state(state: str) -> str:
|
||||
return state
|
||||
|
||||
|
||||
def callback(func: _CallableT) -> _CallableT:
|
||||
def callback[_CallableT: Callable[..., Any]](func: _CallableT) -> _CallableT:
|
||||
"""Annotation to mark method as safe to call from within the event loop."""
|
||||
setattr(func, "_hass_callback", True)
|
||||
return func
|
||||
@ -562,7 +558,7 @@ class HomeAssistant:
|
||||
self.bus.async_fire_internal(EVENT_CORE_CONFIG_UPDATE)
|
||||
self.bus.async_fire_internal(EVENT_HOMEASSISTANT_STARTED)
|
||||
|
||||
def add_job(
|
||||
def add_job[*_Ts](
|
||||
self, target: Callable[[*_Ts], Any] | Coroutine[Any, Any, Any], *args: *_Ts
|
||||
) -> None:
|
||||
"""Add a job to be executed by the event loop or by an executor.
|
||||
@ -586,7 +582,7 @@ class HomeAssistant:
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_add_job(
|
||||
def async_add_job[_R, *_Ts](
|
||||
self,
|
||||
target: Callable[[*_Ts], Coroutine[Any, Any, _R]],
|
||||
*args: *_Ts,
|
||||
@ -595,7 +591,7 @@ class HomeAssistant:
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_add_job(
|
||||
def async_add_job[_R, *_Ts](
|
||||
self,
|
||||
target: Callable[[*_Ts], Coroutine[Any, Any, _R] | _R],
|
||||
*args: *_Ts,
|
||||
@ -604,7 +600,7 @@ class HomeAssistant:
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_add_job(
|
||||
def async_add_job[_R](
|
||||
self,
|
||||
target: Coroutine[Any, Any, _R],
|
||||
*args: Any,
|
||||
@ -612,7 +608,7 @@ class HomeAssistant:
|
||||
) -> asyncio.Future[_R] | None: ...
|
||||
|
||||
@callback
|
||||
def async_add_job(
|
||||
def async_add_job[_R, *_Ts](
|
||||
self,
|
||||
target: Callable[[*_Ts], Coroutine[Any, Any, _R] | _R]
|
||||
| Coroutine[Any, Any, _R],
|
||||
@ -650,7 +646,7 @@ class HomeAssistant:
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_add_hass_job(
|
||||
def async_add_hass_job[_R](
|
||||
self,
|
||||
hassjob: HassJob[..., Coroutine[Any, Any, _R]],
|
||||
*args: Any,
|
||||
@ -660,7 +656,7 @@ class HomeAssistant:
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_add_hass_job(
|
||||
def async_add_hass_job[_R](
|
||||
self,
|
||||
hassjob: HassJob[..., Coroutine[Any, Any, _R] | _R],
|
||||
*args: Any,
|
||||
@ -669,7 +665,7 @@ class HomeAssistant:
|
||||
) -> asyncio.Future[_R] | None: ...
|
||||
|
||||
@callback
|
||||
def async_add_hass_job(
|
||||
def async_add_hass_job[_R](
|
||||
self,
|
||||
hassjob: HassJob[..., Coroutine[Any, Any, _R] | _R],
|
||||
*args: Any,
|
||||
@ -775,7 +771,7 @@ class HomeAssistant:
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_create_task(
|
||||
def async_create_task[_R](
|
||||
self,
|
||||
target: Coroutine[Any, Any, _R],
|
||||
name: str | None = None,
|
||||
@ -801,7 +797,7 @@ class HomeAssistant:
|
||||
return self.async_create_task_internal(target, name, eager_start)
|
||||
|
||||
@callback
|
||||
def async_create_task_internal(
|
||||
def async_create_task_internal[_R](
|
||||
self,
|
||||
target: Coroutine[Any, Any, _R],
|
||||
name: str | None = None,
|
||||
@ -832,7 +828,7 @@ class HomeAssistant:
|
||||
return task
|
||||
|
||||
@callback
|
||||
def async_create_background_task(
|
||||
def async_create_background_task[_R](
|
||||
self, target: Coroutine[Any, Any, _R], name: str, eager_start: bool = True
|
||||
) -> asyncio.Task[_R]:
|
||||
"""Create a task from within the event loop.
|
||||
@ -864,7 +860,7 @@ class HomeAssistant:
|
||||
return task
|
||||
|
||||
@callback
|
||||
def async_add_executor_job(
|
||||
def async_add_executor_job[_T, *_Ts](
|
||||
self, target: Callable[[*_Ts], _T], *args: *_Ts
|
||||
) -> asyncio.Future[_T]:
|
||||
"""Add an executor job from within the event loop."""
|
||||
@ -878,7 +874,7 @@ class HomeAssistant:
|
||||
return task
|
||||
|
||||
@callback
|
||||
def async_add_import_executor_job(
|
||||
def async_add_import_executor_job[_T, *_Ts](
|
||||
self, target: Callable[[*_Ts], _T], *args: *_Ts
|
||||
) -> asyncio.Future[_T]:
|
||||
"""Add an import executor job from within the event loop.
|
||||
@ -935,24 +931,24 @@ class HomeAssistant:
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_run_job(
|
||||
def async_run_job[_R, *_Ts](
|
||||
self, target: Callable[[*_Ts], Coroutine[Any, Any, _R]], *args: *_Ts
|
||||
) -> asyncio.Future[_R] | None: ...
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_run_job(
|
||||
def async_run_job[_R, *_Ts](
|
||||
self, target: Callable[[*_Ts], Coroutine[Any, Any, _R] | _R], *args: *_Ts
|
||||
) -> asyncio.Future[_R] | None: ...
|
||||
|
||||
@overload
|
||||
@callback
|
||||
def async_run_job(
|
||||
def async_run_job[_R](
|
||||
self, target: Coroutine[Any, Any, _R], *args: Any
|
||||
) -> asyncio.Future[_R] | None: ...
|
||||
|
||||
@callback
|
||||
def async_run_job(
|
||||
def async_run_job[_R, *_Ts](
|
||||
self,
|
||||
target: Callable[[*_Ts], Coroutine[Any, Any, _R] | _R]
|
||||
| Coroutine[Any, Any, _R],
|
||||
|
Reference in New Issue
Block a user