Make HassJob job_type lookup lazy (#112563)
This commit is contained in:
parent
a7b4cd3512
commit
e12e129065
2 changed files with 7 additions and 4 deletions
|
@ -289,8 +289,6 @@ class HassJob(Generic[_P, _R_co]):
|
||||||
we run the job.
|
we run the job.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ("job_type", "target", "name", "_cancel_on_shutdown")
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
target: Callable[_P, _R_co],
|
target: Callable[_P, _R_co],
|
||||||
|
@ -302,8 +300,13 @@ class HassJob(Generic[_P, _R_co]):
|
||||||
"""Create a job object."""
|
"""Create a job object."""
|
||||||
self.target = target
|
self.target = target
|
||||||
self.name = name
|
self.name = name
|
||||||
self.job_type = job_type or _get_hassjob_callable_job_type(target)
|
|
||||||
self._cancel_on_shutdown = cancel_on_shutdown
|
self._cancel_on_shutdown = cancel_on_shutdown
|
||||||
|
self._job_type = job_type
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def job_type(self) -> HassJobType:
|
||||||
|
"""Return the job type."""
|
||||||
|
return self._job_type or _get_hassjob_callable_job_type(self.target)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cancel_on_shutdown(self) -> bool | None:
|
def cancel_on_shutdown(self) -> bool | None:
|
||||||
|
|
|
@ -2190,7 +2190,7 @@ async def test_hassjob_forbid_coroutine() -> None:
|
||||||
coro = bla()
|
coro = bla()
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
ha.HassJob(coro)
|
ha.HassJob(coro).job_type
|
||||||
|
|
||||||
# To avoid warning about unawaited coro
|
# To avoid warning about unawaited coro
|
||||||
await coro
|
await coro
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue