Closed
Description
The API documentation for the Request
class indicates the query_params
may be MultiDict
or None
: https://aws.github.io/chalice/api.html#Request.query_params
However, the type hint associated with the class definition does not match the above:
Lines 77 to 78 in 8df8b59
The impact of this issue is that the mismatch makes it more difficult for developers to use the API as their IDE will suggest one thing about query_params
(they don't need to check for None
values) while in reality they do.
A minimal example of such is below, with comments.
from chalice import Chalice, Response
DEFAULT_NAME = "world"
app = Chalice(app_name="hello-world")
@app.route("/", methods=["GET"])
def hello_world():
# This part is not obvious given chalice's current type hints
# `or {}` is a work-around to ensure params is Dict type if chalice sets it as None
params = app.current_request.query_params or {}
# works for Dict/MultiDict, but not NoneType
name = params.get("name", DEFAULT_NAME)
return {"message": f"hello {name}"}
This is an issue on the latest release 1.22.3