Common: Accept Union[str, Type[AbstractEvent]] in EventSerializerRegistry

This commit is contained in:
Ilija Lazoroski 2022-08-18 09:42:05 +02:00
parent 23604009a0
commit a32d9359b0
1 changed files with 10 additions and 6 deletions

View File

@ -1,17 +1,21 @@
from typing import Type, Union
from common.event_serializers import IEventSerializer from common.event_serializers import IEventSerializer
from common.events import AbstractEvent
class EventSerializerRegistry: class EventSerializerRegistry:
""" """
Registry for event serializers Registry for event serializers using event class.
""" """
def __init__(self): def __init__(self):
self._registry = {} self._registry = {}
def __setitem__(self, event_class_name: str, event_serializer: IEventSerializer): def __setitem__(
self._registry[event_class_name] = event_serializer self, event_class: Union[str, Type[AbstractEvent]], event_serializer: IEventSerializer
):
self._registry[event_class] = event_serializer
def __getitem__(self, event_class_name: str): def __getitem__(self, event_class: Union[str, Type[AbstractEvent]]):
event_serializer = self._registry[event_class_name] return self._registry[event_class]
return event_serializer