mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Mark HassJob target as Final (#117578)
This commit is contained in:
parent
121aa158c9
commit
4300ff6b60
@ -35,6 +35,7 @@ from time import monotonic
|
|||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
|
Final,
|
||||||
Generic,
|
Generic,
|
||||||
NotRequired,
|
NotRequired,
|
||||||
ParamSpec,
|
ParamSpec,
|
||||||
@ -325,7 +326,7 @@ class HassJob(Generic[_P, _R_co]):
|
|||||||
job_type: HassJobType | None = None,
|
job_type: HassJobType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a job object."""
|
"""Create a job object."""
|
||||||
self.target = target
|
self.target: Final = target
|
||||||
self.name = name
|
self.name = name
|
||||||
self._cancel_on_shutdown = cancel_on_shutdown
|
self._cancel_on_shutdown = cancel_on_shutdown
|
||||||
self._job_type = job_type
|
self._job_type = job_type
|
||||||
@ -746,9 +747,7 @@ class HomeAssistant:
|
|||||||
# https://github.com/home-assistant/core/pull/71960
|
# https://github.com/home-assistant/core/pull/71960
|
||||||
if hassjob.job_type is HassJobType.Coroutinefunction:
|
if hassjob.job_type is HassJobType.Coroutinefunction:
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
hassjob.target = cast(
|
hassjob = cast(HassJob[..., Coroutine[Any, Any, _R]], hassjob)
|
||||||
Callable[..., Coroutine[Any, Any, _R]], hassjob.target
|
|
||||||
)
|
|
||||||
task = create_eager_task(
|
task = create_eager_task(
|
||||||
hassjob.target(*args), name=hassjob.name, loop=self.loop
|
hassjob.target(*args), name=hassjob.name, loop=self.loop
|
||||||
)
|
)
|
||||||
@ -756,12 +755,12 @@ class HomeAssistant:
|
|||||||
return task
|
return task
|
||||||
elif hassjob.job_type is HassJobType.Callback:
|
elif hassjob.job_type is HassJobType.Callback:
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
hassjob.target = cast(Callable[..., _R], hassjob.target)
|
hassjob = cast(HassJob[..., _R], hassjob)
|
||||||
self.loop.call_soon(hassjob.target, *args)
|
self.loop.call_soon(hassjob.target, *args)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
hassjob.target = cast(Callable[..., _R], hassjob.target)
|
hassjob = cast(HassJob[..., _R], hassjob)
|
||||||
task = self.loop.run_in_executor(None, hassjob.target, *args)
|
task = self.loop.run_in_executor(None, hassjob.target, *args)
|
||||||
|
|
||||||
task_bucket = self._background_tasks if background else self._tasks
|
task_bucket = self._background_tasks if background else self._tasks
|
||||||
@ -936,7 +935,7 @@ class HomeAssistant:
|
|||||||
# https://github.com/home-assistant/core/pull/71960
|
# https://github.com/home-assistant/core/pull/71960
|
||||||
if hassjob.job_type is HassJobType.Callback:
|
if hassjob.job_type is HassJobType.Callback:
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
hassjob.target = cast(Callable[..., _R], hassjob.target)
|
hassjob = cast(HassJob[..., _R], hassjob)
|
||||||
hassjob.target(*args)
|
hassjob.target(*args)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user