Pre-set the HassJob job_type cached_property if its known (#118199)

This commit is contained in:
J. Nick Koston 2024-05-26 16:13:48 -10:00 committed by GitHub
parent 811ec57c31
commit 56431ef750
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -330,12 +330,15 @@ class HassJob[**_P, _R_co]:
self.target: Final = target
self.name = name
self._cancel_on_shutdown = cancel_on_shutdown
self._job_type = job_type
if job_type:
# Pre-set the cached_property so we
# avoid the function call
self.__dict__["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)
return get_hassjob_callable_job_type(self.target)
@property
def cancel_on_shutdown(self) -> bool | None: