feat: simplify data attributes
Signed-off-by: Alexander Tkachev <sasha64sasha@gmail.com>
This commit is contained in:
parent
01041e7cd5
commit
56489682c5
|
@ -25,7 +25,7 @@ class CloudEvent(abc.ABC):
|
||||||
@property
|
@property
|
||||||
def _attributes_read_model(self) -> typing.Dict[str, typing.Any]:
|
def _attributes_read_model(self) -> typing.Dict[str, typing.Any]:
|
||||||
"""
|
"""
|
||||||
:return: dict read model of all of the attributes of this event
|
:return: attributes of this event
|
||||||
|
|
||||||
you MUST NOT mutate this dict
|
you MUST NOT mutate this dict
|
||||||
implementation MAY assume the dic will not be mutated
|
implementation MAY assume the dic will not be mutated
|
||||||
|
@ -33,11 +33,12 @@ class CloudEvent(abc.ABC):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self) -> typing.Optional[typing.Any]:
|
def _data_read_model(self) -> typing.Optional[typing.Any]:
|
||||||
raise NotImplementedError()
|
"""
|
||||||
|
:return: data value of the event
|
||||||
@data.setter
|
you MUST NOT mutate this value
|
||||||
def data(self, value: typing.Optional[typing.Any]) -> None:
|
implementation MAY assume the value will not be mutated
|
||||||
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def __setitem__(self, key: str, value: typing.Any) -> None:
|
def __setitem__(self, key: str, value: typing.Any) -> None:
|
||||||
|
@ -49,7 +50,7 @@ class CloudEvent(abc.ABC):
|
||||||
def __eq__(self, other: typing.Any) -> bool:
|
def __eq__(self, other: typing.Any) -> bool:
|
||||||
if isinstance(other, CloudEvent):
|
if isinstance(other, CloudEvent):
|
||||||
return (
|
return (
|
||||||
self.data == other.data
|
self._data_read_model == other._data_read_model
|
||||||
and self._attributes_read_model == other._attributes_read_model
|
and self._attributes_read_model == other._attributes_read_model
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
@ -85,7 +86,9 @@ class CloudEvent(abc.ABC):
|
||||||
return key in self._attributes_read_model
|
return key in self._attributes_read_model
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return str({"attributes": self._attributes_read_model, "data": self.data})
|
return str(
|
||||||
|
{"attributes": self._attributes_read_model, "data": self._data_read_model}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
AnyCloudEvent = TypeVar("AnyCloudEvent", bound=CloudEvent)
|
AnyCloudEvent = TypeVar("AnyCloudEvent", bound=CloudEvent)
|
||||||
|
|
Loading…
Reference in New Issue