From 984eba809c9977b277991ed60ded3189e9d4c4cc Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 5 Sep 2024 10:16:44 +0200 Subject: [PATCH] Simplify generic decorators in recorder (#125301) * Simplify generic decorators in recorder * Remove additional case --- homeassistant/components/recorder/util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index 9f6cdccd79a..75e403d8204 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -644,7 +644,7 @@ def _is_retryable_error(instance: Recorder, err: OperationalError) -> bool: ) -type _FuncType[_T, **_P, _R] = Callable[Concatenate[_T, _P], _R] +type _FuncType[**P, R] = Callable[Concatenate[Recorder, P], R] type _FuncOrMethType[**_P, _R] = Callable[_P, _R] @@ -683,9 +683,9 @@ def retryable_database_job[**_P]( return decorator -def database_job_retry_wrapper[_RecorderT: Recorder, **_P]( +def database_job_retry_wrapper[**_P]( description: str, attempts: int = 5 -) -> Callable[[_FuncType[_RecorderT, _P, None]], _FuncType[_RecorderT, _P, None]]: +) -> Callable[[_FuncType[_P, None]], _FuncType[_P, None]]: """Try to execute a database job multiple times. This wrapper handles InnoDB deadlocks and lock timeouts. @@ -695,10 +695,10 @@ def database_job_retry_wrapper[_RecorderT: Recorder, **_P]( """ def decorator( - job: _FuncType[_RecorderT, _P, None], - ) -> _FuncType[_RecorderT, _P, None]: + job: _FuncType[_P, None], + ) -> _FuncType[_P, None]: @functools.wraps(job) - def wrapper(instance: _RecorderT, *args: _P.args, **kwargs: _P.kwargs) -> None: + def wrapper(instance: Recorder, *args: _P.args, **kwargs: _P.kwargs) -> None: for attempt in range(attempts): try: job(instance, *args, **kwargs)