From 9cc479117318d61a3908fc5e58beac4b05d4d790 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 11 Jul 2022 14:24:27 +0300 Subject: [PATCH 1/2] feat: add type information for all cloudevent member functions Signed-off-by: Alexander Tkachev --- cloudevents/http/event.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index 83adf398..65368a92 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -67,12 +67,12 @@ def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None): 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 @@ def get( """ 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}) From ba3e26ccb192c3ee3ed09e1afd0a9af67a7757ea Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 20:32:54 +0300 Subject: [PATCH 2/2] docs: update changelog Signed-off-by: Alexander Tkachev --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ec8537..2c724920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -147,3 +148,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#160]: https://github.com/cloudevents/sdk-python/pull/160 [#165]: https://github.com/cloudevents/sdk-python/pull/165 [#167]: https://github.com/cloudevents/sdk-python/pull/167 +[#173]: https://github.com/cloudevents/sdk-python/pull/173