mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Reduce calls to asyncio.iscoroutine (#71090)
This commit is contained in:
parent
5d37cfc61e
commit
26b6952c06
@ -192,18 +192,15 @@ class HassJob(Generic[_R_co]):
|
|||||||
|
|
||||||
def __init__(self, target: Callable[..., _R_co]) -> None:
|
def __init__(self, target: Callable[..., _R_co]) -> None:
|
||||||
"""Create a job object."""
|
"""Create a job object."""
|
||||||
if asyncio.iscoroutine(target):
|
|
||||||
raise ValueError("Coroutine not allowed to be passed to HassJob")
|
|
||||||
|
|
||||||
self.target = target
|
self.target = target
|
||||||
self.job_type = _get_callable_job_type(target)
|
self.job_type = _get_hassjob_callable_job_type(target)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Return the job."""
|
"""Return the job."""
|
||||||
return f"<Job {self.job_type} {self.target}>"
|
return f"<Job {self.job_type} {self.target}>"
|
||||||
|
|
||||||
|
|
||||||
def _get_callable_job_type(target: Callable[..., Any]) -> HassJobType:
|
def _get_hassjob_callable_job_type(target: Callable[..., Any]) -> HassJobType:
|
||||||
"""Determine the job type from the callable."""
|
"""Determine the job type from the callable."""
|
||||||
# Check for partials to properly determine if coroutine function
|
# Check for partials to properly determine if coroutine function
|
||||||
check_target = target
|
check_target = target
|
||||||
@ -214,6 +211,8 @@ def _get_callable_job_type(target: Callable[..., Any]) -> HassJobType:
|
|||||||
return HassJobType.Coroutinefunction
|
return HassJobType.Coroutinefunction
|
||||||
if is_callback(check_target):
|
if is_callback(check_target):
|
||||||
return HassJobType.Callback
|
return HassJobType.Callback
|
||||||
|
if asyncio.iscoroutine(check_target):
|
||||||
|
raise ValueError("Coroutine not allowed to be passed to HassJob")
|
||||||
return HassJobType.Executor
|
return HassJobType.Executor
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user