feat: add type information for all cloudevent member functions (#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>
This commit is contained in:
parent
18951808b1
commit
f39b964209
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Added
|
||||
- Added `.get` accessor for even properties ([#165])
|
||||
- Added type information for all event member functions ([#173])
|
||||
|
||||
### Changed
|
||||
- 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
|
|||
[#168]: https://github.com/cloudevents/sdk-python/pull/168
|
||||
[#169]: https://github.com/cloudevents/sdk-python/pull/169
|
||||
[#170]: https://github.com/cloudevents/sdk-python/pull/170
|
||||
[#173]: https://github.com/cloudevents/sdk-python/pull/173
|
||||
|
|
|
@ -67,12 +67,12 @@ class CloudEvent:
|
|||
f"Missing required keys: {required_set - self._attributes.keys()}"
|
||||
)
|
||||
|
||||
def __eq__(self, other):
|
||||
def __eq__(self, other: typing.Any) -> bool:
|
||||
return self.data == other.data and self._attributes == other._attributes
|
||||
|
||||
# Data access is handled via `.data` member
|
||||
# Attribute access is managed via Mapping type
|
||||
def __getitem__(self, key):
|
||||
def __getitem__(self, key: str) -> typing.Any:
|
||||
return self._attributes[key]
|
||||
|
||||
def get(
|
||||
|
@ -91,20 +91,20 @@ class CloudEvent:
|
|||
"""
|
||||
return self._attributes.get(key, default)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
def __setitem__(self, key: str, value: typing.Any) -> None:
|
||||
self._attributes[key] = value
|
||||
|
||||
def __delitem__(self, key):
|
||||
def __delitem__(self, key: str) -> None:
|
||||
del self._attributes[key]
|
||||
|
||||
def __iter__(self):
|
||||
def __iter__(self) -> typing.Iterator[typing.Any]:
|
||||
return iter(self._attributes)
|
||||
|
||||
def __len__(self):
|
||||
def __len__(self) -> int:
|
||||
return len(self._attributes)
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key: str) -> bool:
|
||||
return key in self._attributes
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return str({"attributes": self._attributes, "data": self.data})
|
||||
|
|
Loading…
Reference in New Issue