You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type annotations: I think werkzeug.wrappers.Request.json can never be None #3067
I think it can never actually return None, because it calls get_json() with all defaults, which is silent=False, making it never return None and raise in those cases instead.
This issue is still current in the latest release and latest unreleased code.
I am using Pyright, and it complains about usages such as flask.request.json["foo"].
The code some_json["foo"] has many reasons to fail, and the situation where it's null should get equal treatment to the situation where it's a list instead.
Preventing only the None case is not meaningful when the other case can still be let through.
Activity
ThiefMaster commentedon Nov 23, 2025
w/o checking the code: What if the request payload is literally
nullwhich, when parsed as json, becomesNone?oprypin commentedon Nov 23, 2025
@ThiefMaster Uhh yes, that's technically true.
However, the intentions of the type annotations around here are clearly the following:
Anymeans "any JSON type" (without special-casing null)Any | Nonemeans the same, OR that it was not provided.You can see this logic applied in the definitions of
get_json()right below.oprypin commentedon Nov 23, 2025
Or from the pragmatic perspective:
The code
some_json["foo"]has many reasons to fail, and the situation where it's null should get equal treatment to the situation where it's a list instead.Preventing only the
Nonecase is not meaningful when the other case can still be let through.