From 56431ef750e8dea2c1cb968ef7eb4a213802c3a2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 26 May 2024 16:13:48 -1000 Subject: [PATCH] Pre-set the HassJob job_type cached_property if its known (#118199) --- homeassistant/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 9c5d8612b27..573ddde05ba 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -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: