Skip to content

Commit 3978caf

Browse files
committed
chore(docs): move docstrings from implementation to protocol class
Signed-off-by: Tudor Plugaru <[email protected]>
1 parent fbcfba9 commit 3978caf

File tree

2 files changed

+97
-85
lines changed

2 files changed

+97
-85
lines changed

src/cloudevents/core/base.py

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,113 @@
1818

1919

2020
class BaseCloudEvent(Protocol):
21+
"""
22+
The CloudEvent Python wrapper contract exposing generically-available
23+
properties and APIs.
24+
25+
Implementations might handle fields and have other APIs exposed but are
26+
obliged to follow this contract.
27+
"""
28+
2129
def __init__(
2230
self, attributes: dict[str, Any], data: Optional[Union[dict, str, bytes]] = None
23-
) -> None: ...
31+
) -> None:
32+
"""
33+
Create a new CloudEvent instance.
34+
35+
:param attributes: The attributes of the CloudEvent instance.
36+
:param data: The payload of the CloudEvent instance.
37+
38+
:raises ValueError: If any of the required attributes are missing or have invalid values.
39+
:raises TypeError: If any of the attributes have invalid types.
40+
"""
41+
...
42+
43+
def get_id(self) -> str:
44+
"""
45+
Retrieve the ID of the event.
46+
47+
:return: The ID of the event.
48+
"""
49+
...
50+
51+
def get_source(self) -> str:
52+
"""
53+
Retrieve the source of the event.
54+
55+
:return: The source of the event.
56+
"""
57+
...
58+
59+
def get_type(self) -> str:
60+
"""
61+
Retrieve the type of the event.
62+
63+
:return: The type of the event.
64+
"""
65+
...
66+
67+
def get_specversion(self) -> str:
68+
"""
69+
Retrieve the specversion of the event.
70+
71+
:return: The specversion of the event.
72+
"""
73+
...
74+
75+
def get_datacontenttype(self) -> Optional[str]:
76+
"""
77+
Retrieve the datacontenttype of the event.
78+
79+
:return: The datacontenttype of the event.
80+
"""
81+
...
82+
83+
def get_dataschema(self) -> Optional[str]:
84+
"""
85+
Retrieve the dataschema of the event.
2486
25-
def get_id(self) -> str: ...
87+
:return: The dataschema of the event.
88+
"""
89+
...
2690

27-
def get_source(self) -> str: ...
91+
def get_subject(self) -> Optional[str]:
92+
"""
93+
Retrieve the subject of the event.
2894
29-
def get_type(self) -> str: ...
95+
:return: The subject of the event.
96+
"""
97+
...
3098

31-
def get_specversion(self) -> str: ...
99+
def get_time(self) -> Optional[datetime]:
100+
"""
101+
Retrieve the time of the event.
32102
33-
def get_datacontenttype(self) -> Optional[str]: ...
103+
:return: The time of the event.
104+
"""
105+
...
34106

35-
def get_dataschema(self) -> Optional[str]: ...
107+
def get_extension(self, extension_name: str) -> Any:
108+
"""
109+
Retrieve an extension attribute of the event.
36110
37-
def get_subject(self) -> Optional[str]: ...
111+
:param extension_name: The name of the extension attribute.
112+
:return: The value of the extension attribute.
113+
"""
114+
...
38115

39-
def get_time(self) -> Optional[datetime]: ...
116+
def get_data(self) -> Optional[Union[dict, str, bytes]]:
117+
"""
118+
Retrieve data of the event.
40119
41-
def get_extension(self, extension_name: str) -> Any: ...
120+
:return: The data of the event.
121+
"""
122+
...
42123

43-
def get_data(self) -> Optional[Union[dict, str, bytes]]: ...
124+
def get_attributes(self) -> dict[str, Any]:
125+
"""
126+
Retrieve all attributes of the event.
44127
45-
def get_attributes(self) -> dict[str, Any]: ...
128+
:return: The attributes of the event.
129+
"""
130+
...

src/cloudevents/core/v1/event.py

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,9 @@
3737

3838

3939
class CloudEvent(BaseCloudEvent):
40-
"""
41-
The CloudEvent Python wrapper contract exposing generically-available
42-
properties and APIs.
43-
44-
Implementations might handle fields and have other APIs exposed but are
45-
obliged to follow this contract.
46-
"""
47-
4840
def __init__(
4941
self, attributes: dict[str, Any], data: Optional[Union[dict, str, bytes]] = None
5042
) -> None:
51-
"""
52-
Create a new CloudEvent instance.
53-
54-
:param attributes: The attributes of the CloudEvent instance.
55-
:param data: The payload of the CloudEvent instance.
56-
57-
:raises ValueError: If any of the required attributes are missing or have invalid values.
58-
:raises TypeError: If any of the attributes have invalid types.
59-
"""
6043
self._validate_attribute(attributes=attributes)
6144
self._attributes: dict[str, Any] = attributes
6245
self._data: Optional[Union[dict, str, bytes]] = data
@@ -246,90 +229,34 @@ def _validate_extension_attributes(
246229
return errors
247230

248231
def get_id(self) -> str:
249-
"""
250-
Retrieve the ID of the event.
251-
252-
:return: The ID of the event.
253-
"""
254232
return self._attributes["id"] # type: ignore
255233

256234
def get_source(self) -> str:
257-
"""
258-
Retrieve the source of the event.
259-
260-
:return: The source of the event.
261-
"""
262235
return self._attributes["source"] # type: ignore
263236

264237
def get_type(self) -> str:
265-
"""
266-
Retrieve the type of the event.
267-
268-
:return: The type of the event.
269-
"""
270238
return self._attributes["type"] # type: ignore
271239

272240
def get_specversion(self) -> str:
273-
"""
274-
Retrieve the specversion of the event.
275-
276-
:return: The specversion of the event.
277-
"""
278241
return self._attributes["specversion"] # type: ignore
279242

280243
def get_datacontenttype(self) -> Optional[str]:
281-
"""
282-
Retrieve the datacontenttype of the event.
283-
284-
:return: The datacontenttype of the event.
285-
"""
286244
return self._attributes.get("datacontenttype")
287245

288246
def get_dataschema(self) -> Optional[str]:
289-
"""
290-
Retrieve the dataschema of the event.
291-
292-
:return: The dataschema of the event.
293-
"""
294247
return self._attributes.get("dataschema")
295248

296249
def get_subject(self) -> Optional[str]:
297-
"""
298-
Retrieve the subject of the event.
299-
300-
:return: The subject of the event.
301-
"""
302250
return self._attributes.get("subject")
303251

304252
def get_time(self) -> Optional[datetime]:
305-
"""
306-
Retrieve the time of the event.
307-
308-
:return: The time of the event.
309-
"""
310253
return self._attributes.get("time")
311254

312255
def get_extension(self, extension_name: str) -> Any:
313-
"""
314-
Retrieve an extension attribute of the event.
315-
316-
:param extension_name: The name of the extension attribute.
317-
:return: The value of the extension attribute.
318-
"""
319256
return self._attributes.get(extension_name)
320257

321258
def get_data(self) -> Optional[Union[dict, str, bytes]]:
322-
"""
323-
Retrieve data of the event.
324-
325-
:return: The data of the event.
326-
"""
327259
return self._data
328260

329261
def get_attributes(self) -> dict[str, Any]:
330-
"""
331-
Retrieve all attributes of the event.
332-
333-
:return: The attributes of the event.
334-
"""
335262
return self._attributes

0 commit comments

Comments
 (0)