From dca72c598ed025736603985cd16ab966397a6ba8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 3 Nov 2023 14:58:03 -0500 Subject: [PATCH] Small speed up to async_listen (#103307) Avoid constructing an inner function each time we call async_listen and use a partial which holds a reference to the function body with new args instead of making another full function --- homeassistant/core.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 40e9da376d5..ab0fa3b6892 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1176,12 +1176,9 @@ class EventBus: self, event_type: str, filterable_job: _FilterableJobType ) -> CALLBACK_TYPE: self._listeners.setdefault(event_type, []).append(filterable_job) - - def remove_listener() -> None: - """Remove the listener.""" - self._async_remove_listener(event_type, filterable_job) - - return remove_listener + return functools.partial( + self._async_remove_listener, event_type, filterable_job + ) def listen_once( self,