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

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

Open
dupuyarc opened this issue Feb 16, 2024 · 0 comments

Comments

@dupuyarc
Copy link

dupuyarc commented Feb 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant