The type signature for Response.get_json is currently:
def get_json(self, force: bool = False, silent: bool = False) -> t.Optional[t.Any]:
However, if silent is False, as is the default, this is overbroad, since it will always return t.Any. This is problematic in calling code, since you'll get a type checking error if you do something like this:
error: Value of type "Optional[Any]" is not indexable [index]
data = rv.get_json()["data"]
This can be fixed by using an overload from the typing module when silent is the Literal[False]
Environment:
- Python version: 3.9.6
- Werkzeug version: 2.1.2
The type signature for
Response.get_jsonis currently:However, if
silentisFalse, as is the default, this is overbroad, since it will always returnt.Any. This is problematic in calling code, since you'll get a type checking error if you do something like this:This can be fixed by using an
overloadfrom thetypingmodule whensilentis theLiteral[False]Environment: