Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type information for all cloudevent member functions #173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
16 changes: 8 additions & 8 deletions cloudevents/http/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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})