Skip to content

docs: clarify abstract.CloudEvent docstring (attributes vs data) - #302

Open
manduinca wants to merge 2 commits into
cloudevents:mainfrom
manduinca:docs/247-abstract-cloudevent-docstring
Open

manduinca wants to merge 2 commits into
cloudevents:mainfrom
manduinca:docs/247-abstract-cloudevent-docstring

Conversation

@manduinca

Copy link
Copy Markdown

Fixes #247

Reworks the abstract.CloudEvent docstring to explain the attributes vs data split that a couple of people found confusing in the issue. It now lists the required (id, source, type, specversion) and optional attributes, links to the CloudEvents spec, notes the class is abstract, and adds a runnable example.

It also documents on __getitem__ and get why the payload is not reachable through the mapping interface, so event["data"] raises KeyError and event.get("data") returns the default instead of the payload.

The file moved from cloudevents/abstract/event.py to src/cloudevents/v1/abstract/event.py since the issue was filed, so this updates it there. Docstrings only, no behavior change.

Explain the attributes-vs-data split, list the required and optional
CloudEvents v1.0 attributes with a spec reference, and add a usage
example. Document why the mapping interface (__getitem__/get) exposes
context attributes only and why the payload must be read via .data.

Fixes cloudevents#247

Signed-off-by: Jean Pierre Mandujano G. <jeanpierre.mandujano@gmail.com>
@manduinca
manduinca force-pushed the docs/247-abstract-cloudevent-docstring branch from 7029159 to 1487fae Compare September 20, 2026 08:47
@duglin
duglin requested a balanced review from Copilot November 29, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The documentation incorrectly claims that direct instantiation is prohibited and that data lookups always raise KeyError or return a default, overlooking a separate data attribute.

2 open issues
What changed in this PR

This documentation-only PR addresses #247 by clarifying the distinction between CloudEvent context attributes and payload data in the shared abstract contract.

Changes:

  • Lists required and optional attributes and links to the CloudEvents specification.
  • Describes the class’s intended abstract role and adds a usage example.
  • Explains payload access through .data or get_data, separately from mapping access.
File Description
src/​cloudevents/​v1/​abstract/​event.py Expands class, __getitem__, and get docstrings without changing runtime behavior.

Review effort: Balanced

Comment thread src/cloudevents/v1/abstract/event.py Outdated
Comment on lines +44 to +45
Pydantic variants). It is abstract and cannot be instantiated directly;
use a concrete subclass or its `create` factory instead.
Comment thread src/cloudevents/v1/abstract/event.py Outdated
Comment on lines +49 to +52
interface exposes the attributes only: the event `data` is never part of
it and must be read through the `.data` accessor (or `get_data`). This is
why `event["data"]` raises a `KeyError` and `event.get("data")` returns the
default instead of the payload.
I clarified which base methods are unimplemented and how HTTP attribute lookups interact with the event payload.

Signed-off-by: Jean Pierre Mandujano G. <jeanpierre.mandujano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the docstring of abstract.CloudEvent

3 participants