Skip to content

Commit

Permalink
Simplify generic decorators in recorder (#125301)
Browse files Browse the repository at this point in the history
* Simplify generic decorators in recorder

* Remove additional case
  • Loading branch information
emontnemery authored Sep 5, 2024
1 parent f778033 commit 984eba8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions homeassistant/components/recorder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down Expand Up @@ -683,9 +683,9 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> bool:
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.
Expand All @@ -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)
Expand Down

0 comments on commit 984eba8

Please sign in to comment.