From f39b964209babfbcd6a17502b9873cd87df7e6f0 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 22:44:43 +0300 Subject: [PATCH] feat: add type information for all cloudevent member functions (#173) * feat: add type information for all cloudevent member functions Signed-off-by: Alexander Tkachev * docs: update changelog Signed-off-by: Alexander Tkachev --- CHANGELOG.md | 2 ++ cloudevents/http/event.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8a9ad7..3e1891b 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]) @@ -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 diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index e867f44..b4ef41a 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -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})