From 0e2b165c158c69d512dccc7724797c93b77d3866 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 16 Sep 2022 12:18:50 +0530 Subject: [PATCH] Agent: Rename IEventSerializer -> IAgentEventSerializer --- monkey/common/event_serializers/__init__.py | 2 +- .../event_serializers/event_serializer_registry.py | 12 +++++++----- .../common/event_serializers/i_event_serializer.py | 2 +- .../event_serializers/pydantic_event_serializer.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/monkey/common/event_serializers/__init__.py b/monkey/common/event_serializers/__init__.py index c654f75f6..ac26002a5 100644 --- a/monkey/common/event_serializers/__init__.py +++ b/monkey/common/event_serializers/__init__.py @@ -1,5 +1,5 @@ from .consts import EVENT_TYPE_FIELD -from .i_event_serializer import IEventSerializer, JSONSerializable +from .i_event_serializer import IAgentEventSerializer, JSONSerializable from .event_serializer_registry import EventSerializerRegistry from .pydantic_event_serializer import PydanticEventSerializer from .register import register_common_agent_event_serializers diff --git a/monkey/common/event_serializers/event_serializer_registry.py b/monkey/common/event_serializers/event_serializer_registry.py index b4f43f7b0..09134798b 100644 --- a/monkey/common/event_serializers/event_serializer_registry.py +++ b/monkey/common/event_serializers/event_serializer_registry.py @@ -1,6 +1,6 @@ from typing import Type, Union -from common.event_serializers import IEventSerializer +from common.event_serializers import IAgentEventSerializer from common.events import AbstractAgentEvent @@ -22,18 +22,20 @@ class EventSerializerRegistry: self._registry = {} def __setitem__( - self, event_class: Type[AbstractAgentEvent], event_serializer: IEventSerializer + self, event_class: Type[AbstractAgentEvent], event_serializer: IAgentEventSerializer ): if not issubclass(event_class, AbstractAgentEvent): raise TypeError(f"Event class must be of type: {AbstractAgentEvent.__name__}") - if not isinstance(event_serializer, IEventSerializer): - raise TypeError(f"Event serializer must be of type: {IEventSerializer.__name__}") + if not isinstance(event_serializer, IAgentEventSerializer): + raise TypeError(f"Event serializer must be of type: {IAgentEventSerializer.__name__}") self._registry[event_class] = event_serializer self._registry[event_class.__name__] = event_serializer - def __getitem__(self, event_class: Union[str, Type[AbstractAgentEvent]]) -> IEventSerializer: + def __getitem__( + self, event_class: Union[str, Type[AbstractAgentEvent]] + ) -> IAgentEventSerializer: if not (isinstance(event_class, str) or issubclass(event_class, AbstractAgentEvent)): raise TypeError( f"Registry get key {event_class} must be of type: {AbstractAgentEvent.__name__} or " diff --git a/monkey/common/event_serializers/i_event_serializer.py b/monkey/common/event_serializers/i_event_serializer.py index dd6d9ef19..9a56fcc65 100644 --- a/monkey/common/event_serializers/i_event_serializer.py +++ b/monkey/common/event_serializers/i_event_serializer.py @@ -14,7 +14,7 @@ JSONSerializable = Union[ # type: ignore[misc] ] -class IEventSerializer(ABC): +class IAgentEventSerializer(ABC): """ Manages serialization and deserialization of events """ diff --git a/monkey/common/event_serializers/pydantic_event_serializer.py b/monkey/common/event_serializers/pydantic_event_serializer.py index 2291f3de9..dfc265865 100644 --- a/monkey/common/event_serializers/pydantic_event_serializer.py +++ b/monkey/common/event_serializers/pydantic_event_serializer.py @@ -4,14 +4,14 @@ from typing import Generic, Type, TypeVar from common.events import AbstractAgentEvent from common.utils.code_utils import del_key -from . import EVENT_TYPE_FIELD, IEventSerializer, JSONSerializable +from . import EVENT_TYPE_FIELD, IAgentEventSerializer, JSONSerializable logger = logging.getLogger(__name__) T = TypeVar("T", bound=AbstractAgentEvent) -class PydanticEventSerializer(IEventSerializer, Generic[T]): +class PydanticEventSerializer(IAgentEventSerializer, Generic[T]): def __init__(self, event_class: Type[T]): self._event_class = event_class