Skip to content

Should event metadata be in attribute docstrings? #564

@bradenmacdonald

Description

@bradenmacdonald

Currently, the data types for events are nicely integrated with VS Code and other tooling:

Image

But this is not the case for events themselves. A lot of the key information is in comments like this:

# .. event_type: org.openedx.content_authoring.content.object.tags.changed.v1
# .. event_name: CONTENT_OBJECT_TAGS_CHANGED
# .. event_description: Emitted when an object's tags are changed.
# .. event_data: ContentObjectData
# .. event_warning: **DEPRECATED** please use CONTENT_OBJECT_ASSOCIATIONS_CHANGED instead.
CONTENT_OBJECT_TAGS_CHANGED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.content.object.tags.changed.v1",
data={
"content_object": ContentObjectData,
}
)

Which does not appear in relevant places in VS Code:

Image

However, if we were to update our approach to put this data into "attribute docstrings" (as defined in PEP 257), then this information would show up in VS Code (as well as other tools like mkdocstrings):

Image

😎

The code I used for the above screenshot looks like this:

CONTENT_OBJECT_TAGS_CHANGED = OpenEdxPublicSignal(
    event_type="org.openedx.content_authoring.content.object.tags.changed.v1",
    data={
        "content_object": ContentObjectData,
    }
)
"""
Emitted when an object's tags are changed.

**Warning**: This is DEPRECATED; please use `CONTENT_OBJECT_ASSOCIATIONS_CHANGED` instead.

Details |:
-|-
event_type | `org.openedx.content_authoring.content.object.tags.changed.v1`
event_name | `CONTENT_OBJECT_TAGS_CHANGED`
event_data | `content_object`: `ContentObjectData`
"""

Such attribute docstrings are not normally accessible at runtime (same as with the current comment approach), but you can use the griffe module to access them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions