Skip to content

Export event classes (or at least BaseLambdaEvent) or provide typeshed stub library #2094

Open
@dupuyarc

Description

The Chalice documentation for the CloudWatchEvent class gives an example function with a type annotation:

@app.schedule('rate(1 hour)')
def every_hour(event: CloudWatchEvent):
    pass

However, the chalice package does not export this type in init.py, so there is no importable definition of the class to use, which results in errors from IDEs and type-checkers like MyPy.

Exporting all the event classes would prevent the error in a type annotation, but may generate warnings when attributes are referenced, since those appear to be dynamically generated for each subclass. There might not be much advantage over just exporting the BaseLambdaEvent class as a "minimum viable type checking" solution.

It might be better to create a separate type stub library that can be imported if TYPE_CHECKING: that provides dummy classes with the specific attributes actually created for each event class.

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