aws / aws/chalice

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

Open
#2,094 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
11.1k
Forks
1k
Avg merge
1d 22h
Merged PRs (30d)
2

Description

The [Chalice documentation for the CloudWatchEvent class](https://aws.github.io/chalice/api.html#CloudWatchEvent) 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](https://github.com/aws/chalice/blob/master/chalice/__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](https://typing.readthedocs.io/en/latest/source/stubs.html) that can be imported `if TYPE_CHECKING:` that provides dummy classes with the specific attributes actually created for each event class.

Contributor guide

Open the contributing guide

Research direction

Start with chalice/__init__.py and the CloudWatchEvent example in the documentation, then locate the event-class definitions and inspect BaseLambdaEvent. Compare exporting the classes with providing a type-stub library for TYPE_CHECKING, including the dynamically created attributes. Done means the documented annotation is importable and type-checkers no longer report the missing event type.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
backend, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.