From 06efe1a169564e5f883b1f0162e99349375d8725 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Tue, 31 Dec 2019 20:16:24 -0500 Subject: [PATCH] Add get_handler_by_type() method in Processor --- .../tracetools_analysis/processor/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tracetools_analysis/tracetools_analysis/processor/__init__.py b/tracetools_analysis/tracetools_analysis/processor/__init__.py index 7de0ae0..c55e8e1 100644 --- a/tracetools_analysis/tracetools_analysis/processor/__init__.py +++ b/tracetools_analysis/tracetools_analysis/processor/__init__.py @@ -332,6 +332,18 @@ class Processor(): for handler in handlers: handler.register_processor(self) + def get_handler_by_type( + self, + handler_type: Type, + ) -> Union[EventHandler, None]: + """ + Get an existing EventHandler instance from its type. + + :param handler_type: the type of EventHandler subclass to find + :return: the EventHandler instance if found, otherwise `None` + """ + return next((handler for handler in self._expanded_handlers if type(handler) is handler_type), None) + @staticmethod def get_event_names( events: List[DictEvent],