From 3cef54c09c00933b192dc6e8a9df469e18f08a2d Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 9 Aug 2022 11:53:03 +0530 Subject: [PATCH] Common: Change IEventQueue and PyPubSubEventQueue's subscribe_types() -> subscribe_type() --- monkey/common/event_queue/i_event_queue.py | 10 ++++------ monkey/common/event_queue/pypubsub_event_queue.py | 13 +++++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/monkey/common/event_queue/i_event_queue.py b/monkey/common/event_queue/i_event_queue.py index 47788f263..c119726f4 100644 --- a/monkey/common/event_queue/i_event_queue.py +++ b/monkey/common/event_queue/i_event_queue.py @@ -1,5 +1,5 @@ from abc import ABC, abstractstaticmethod -from typing import Any, Callable, Sequence +from typing import Any, Callable from common.events import AbstractEvent @@ -20,13 +20,11 @@ class IEventQueue(ABC): pass @abstractstaticmethod - def subscribe_types( - types: Sequence[AbstractEvent], subscriber: Callable[[AbstractEvent], None] - ): + def subscribe_type(event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]): """ - Subscribes a subscriber to all specifed event types + Subscribes a subscriber to the specifed event type - :param types: Event types to which the subscriber should subscribe + :param event_type: Event type to which the subscriber should subscribe :param subscriber: Callable that should subscribe to events """ diff --git a/monkey/common/event_queue/pypubsub_event_queue.py b/monkey/common/event_queue/pypubsub_event_queue.py index 711187577..6ea4111f9 100644 --- a/monkey/common/event_queue/pypubsub_event_queue.py +++ b/monkey/common/event_queue/pypubsub_event_queue.py @@ -1,4 +1,4 @@ -from typing import Any, Callable, Sequence +from typing import Any, Callable from pubsub import pub @@ -13,13 +13,10 @@ class PyPubSubEventQueue(IEventQueue): pub.subscribe(listener=subscriber, topicName=pub.ALL_TOPICS) @staticmethod - def subscribe_types( - types: Sequence[AbstractEvent], subscriber: Callable[[AbstractEvent], None] - ): - for event_type in types: - # pypubsub.pub.subscribe needs a string as the topic/event name - event_type_name = event_type.__name__ - pub.subscribe(listener=subscriber, topicName=event_type_name) + def subscribe_type(event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]): + # pypubsub.pub.subscribe needs a string as the topic/event name + event_type_name = event_type.__name__ + pub.subscribe(listener=subscriber, topicName=event_type_name) @staticmethod def subscribe_tag(tag: str, subscriber: Callable[[AbstractEvent], None]):