Skip to content

Commit f39b964

Browse files
feat: add type information for all cloudevent member functions (cloudevents#173)
* feat: add type information for all cloudevent member functions Signed-off-by: Alexander Tkachev <sasha64sasha@gmail.com> * docs: update changelog Signed-off-by: Alexander Tkachev <sasha64sasha@gmail.com>
1 parent 1895180 commit f39b964

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- Added `.get` accessor for even properties ([#165])
11+
- Added type information for all event member functions ([#173])
1112

1213
### Changed
1314
- Code quality and styling tooling is unified and configs compatibility is ensured ([#167])
@@ -155,3 +156,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
155156
[#168]: https://github.com/cloudevents/sdk-python/pull/168
156157
[#169]: https://github.com/cloudevents/sdk-python/pull/169
157158
[#170]: https://github.com/cloudevents/sdk-python/pull/170
159+
[#173]: https://github.com/cloudevents/sdk-python/pull/173

cloudevents/http/event.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None):
6767
f"Missing required keys: {required_set - self._attributes.keys()}"
6868
)
6969

70-
def __eq__(self, other):
70+
def __eq__(self, other: typing.Any) -> bool:
7171
return self.data == other.data and self._attributes == other._attributes
7272

7373
# Data access is handled via `.data` member
7474
# Attribute access is managed via Mapping type
75-
def __getitem__(self, key):
75+
def __getitem__(self, key: str) -> typing.Any:
7676
return self._attributes[key]
7777

7878
def get(
@@ -91,20 +91,20 @@ def get(
9191
"""
9292
return self._attributes.get(key, default)
9393

94-
def __setitem__(self, key, value):
94+
def __setitem__(self, key: str, value: typing.Any) -> None:
9595
self._attributes[key] = value
9696

97-
def __delitem__(self, key):
97+
def __delitem__(self, key: str) -> None:
9898
del self._attributes[key]
9999

100-
def __iter__(self):
100+
def __iter__(self) -> typing.Iterator[typing.Any]:
101101
return iter(self._attributes)
102102

103-
def __len__(self):
103+
def __len__(self) -> int:
104104
return len(self._attributes)
105105

106-
def __contains__(self, key):
106+
def __contains__(self, key: str) -> bool:
107107
return key in self._attributes
108108

109-
def __repr__(self):
109+
def __repr__(self) -> str:
110110
return str({"attributes": self._attributes, "data": self.data})

0 commit comments

Comments
 (0)