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

Use PEP 695 for function annotations (2) (#117659)

This commit is contained in:
Marc Mueller
2024-05-18 11:44:39 +02:00
committed by GitHub
parent 4cf0a3f154
commit 900b6211ef
10 changed files with 30 additions and 73 deletions

View File

@@ -7,16 +7,13 @@ from collections.abc import Callable, Coroutine, Generator
from contextlib import contextmanager
from contextvars import ContextVar
from functools import wraps
from typing import Any, TypeVar, TypeVarTuple
from typing import Any
from homeassistant.core import ServiceResponse
import homeassistant.util.dt as dt_util
from .typing import TemplateVarsType
_T = TypeVar("_T")
_Ts = TypeVarTuple("_Ts")
class TraceElement:
"""Container for trace data."""
@@ -135,7 +132,9 @@ def trace_id_get() -> tuple[str, str] | None:
return trace_id_cv.get()
def trace_stack_push(trace_stack_var: ContextVar[list[_T] | None], node: _T) -> None:
def trace_stack_push[_T](
trace_stack_var: ContextVar[list[_T] | None], node: _T
) -> None:
"""Push an element to the top of a trace stack."""
trace_stack: list[_T] | None
if (trace_stack := trace_stack_var.get()) is None:
@@ -151,7 +150,7 @@ def trace_stack_pop(trace_stack_var: ContextVar[list[Any] | None]) -> None:
trace_stack.pop()
def trace_stack_top(trace_stack_var: ContextVar[list[_T] | None]) -> _T | None:
def trace_stack_top[_T](trace_stack_var: ContextVar[list[_T] | None]) -> _T | None:
"""Return the element at the top of a trace stack."""
trace_stack = trace_stack_var.get()
return trace_stack[-1] if trace_stack else None
@@ -261,7 +260,7 @@ def trace_path(suffix: str | list[str]) -> Generator[None, None, None]:
trace_path_pop(count)
def async_trace_path(
def async_trace_path[*_Ts](
suffix: str | list[str],
) -> Callable[
[Callable[[*_Ts], Coroutine[Any, Any, None]]],