mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Correct return typing for catch_log_exception
(#78399)
This commit is contained in:
parent
5a6a474bbe
commit
35221e9a61
@ -120,27 +120,30 @@ def log_exception(format_err: Callable[..., Any], *args: Any) -> None:
|
|||||||
def catch_log_exception(
|
def catch_log_exception(
|
||||||
func: Callable[..., Coroutine[Any, Any, Any]], format_err: Callable[..., Any]
|
func: Callable[..., Coroutine[Any, Any, Any]], format_err: Callable[..., Any]
|
||||||
) -> Callable[..., Coroutine[Any, Any, None]]:
|
) -> Callable[..., Coroutine[Any, Any, None]]:
|
||||||
"""Overload for Callables that return a Coroutine."""
|
"""Overload for Coroutine that returns a Coroutine."""
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def catch_log_exception(
|
def catch_log_exception(
|
||||||
func: Callable[..., Any], format_err: Callable[..., Any]
|
func: Callable[..., Any], format_err: Callable[..., Any]
|
||||||
) -> Callable[..., None | Coroutine[Any, Any, None]]:
|
) -> Callable[..., None] | Callable[..., Coroutine[Any, Any, None]]:
|
||||||
"""Overload for Callables that return Any."""
|
"""Overload for a callback that returns a callback."""
|
||||||
|
|
||||||
|
|
||||||
def catch_log_exception(
|
def catch_log_exception(
|
||||||
func: Callable[..., Any], format_err: Callable[..., Any]
|
func: Callable[..., Any], format_err: Callable[..., Any]
|
||||||
) -> Callable[..., None | Coroutine[Any, Any, None]]:
|
) -> Callable[..., None] | Callable[..., Coroutine[Any, Any, None]]:
|
||||||
"""Decorate a callback to catch and log exceptions."""
|
"""Decorate a function func to catch and log exceptions.
|
||||||
|
|
||||||
|
If func is a coroutine function, a coroutine function will be returned.
|
||||||
|
If func is a callback, a callback will be returned.
|
||||||
|
"""
|
||||||
# Check for partials to properly determine if coroutine function
|
# Check for partials to properly determine if coroutine function
|
||||||
check_func = func
|
check_func = func
|
||||||
while isinstance(check_func, partial):
|
while isinstance(check_func, partial):
|
||||||
check_func = check_func.func
|
check_func = check_func.func
|
||||||
|
|
||||||
wrapper_func: Callable[..., None | Coroutine[Any, Any, None]]
|
wrapper_func: Callable[..., None] | Callable[..., Coroutine[Any, Any, None]]
|
||||||
if asyncio.iscoroutinefunction(check_func):
|
if asyncio.iscoroutinefunction(check_func):
|
||||||
async_func = cast(Callable[..., Coroutine[Any, Any, None]], func)
|
async_func = cast(Callable[..., Coroutine[Any, Any, None]], func)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user