@@ -26,55 +26,27 @@ def create(
2626 raise NotImplementedError ()
2727
2828 @property
29- def _attributes_read_model (self ) -> typing .Dict [str , typing .Any ]:
29+ def attributes (self ) -> typing .Dict [str , typing .Any ]:
3030 """
3131 :return: Attributes of this event.
3232
3333 You MUST NOT mutate this dict.
3434 Implementation MAY assume the dict will not be mutated.
35-
36- The reason this is only a read model and not a write model is
37- because you MAY not have an easy write access to the data.
38-
39- For example - a database row or a cached value.
40-
41- We don't wont to restrict our future selves.
42-
43- When a write model will be needed, it will be implemented
44-
45- The we don't have an `attributes` property is to prevent API confusion
46- Examples of confusion:
47- * What is the difference between `event.get("myattr")` and
48- `event.attributes.get("myattr")`
49- * What SHOULD I use `event["myattr"]` or `event.attributes["myattr"]` ?
5035 """
5136 raise NotImplementedError ()
5237
5338 @property
54- def _data_read_model (self ) -> typing .Optional [typing .Any ]:
39+ def data (self ) -> typing .Optional [typing .Any ]:
5540 """
5641 :return: Data value of the event.
5742 You MUST NOT mutate this dict.
5843 Implementation MAY assume the dict will not be mutated.
59-
60- The reason this is only a read model and not a write model is
61- because you MAY not have an easy write access to the data.
62-
63- For example - a database row or a cached value.
64-
65- We don't wont to restrict our future selves.
66-
67- When a write model will be needed, it will be implemented
68-
6944 """
7045 raise NotImplementedError ()
7146
7247 def __eq__ (self , other : typing .Any ) -> bool :
7348 if isinstance (other , CloudEvent ):
74- return (
75- self ._data_read_model == other ._data_read_model
76- and self ._attributes_read_model == other ._attributes_read_model
77- )
49+ return self .data == other .data and self .attributes == other .attributes
7850 return False
7951
8052 def __getitem__ (self , key : str ) -> typing .Any :
@@ -84,7 +56,7 @@ def __getitem__(self, key: str) -> typing.Any:
8456 :param key: The event attribute name.
8557 :return: The event attribute value.
8658 """
87- return self ._attributes_read_model [key ]
59+ return self .attributes [key ]
8860
8961 def get (
9062 self , key : str , default : typing .Optional [typing .Any ] = None
@@ -100,21 +72,19 @@ def get(
10072 no attribute with the given key exists.
10173 :returns: The event attribute value if exists, default value otherwise.
10274 """
103- return self ._attributes_read_model .get (key , default )
75+ return self .attributes .get (key , default )
10476
10577 def __iter__ (self ) -> typing .Iterator [typing .Any ]:
106- return iter (self ._attributes_read_model )
78+ return iter (self .attributes )
10779
10880 def __len__ (self ) -> int :
109- return len (self ._attributes_read_model )
81+ return len (self .attributes )
11082
11183 def __contains__ (self , key : str ) -> bool :
112- return key in self ._attributes_read_model
84+ return key in self .attributes
11385
11486 def __repr__ (self ) -> str :
115- return str (
116- {"attributes" : self ._attributes_read_model , "data" : self ._data_read_model }
117- )
87+ return str ({"attributes" : self .attributes , "data" : self .data })
11888
11989
12090AnyCloudEvent = TypeVar ("AnyCloudEvent" , bound = CloudEvent )
0 commit comments