fix: allow None as return type for http 204
Fixes #9424
If the return annotation of the route function is exactly "None", return None for the typed annotation. This allows the status code 204 No Content to be used.
📝 Docs preview for commit 243f74ac0b87a5f24a6823144e951f34d8782946 at: https://6442a49fa75498079da29ef3--fastapi.netlify.app
📝 Docs preview for commit bb5ef4abbc8865a51fab0236503695b30a1ce3b3 at: https://647f33cb7357732441e2ff02--fastapi.netlify.app
I tested this using pip install git+https://github.com/hofrob/fastapi@fix-return-no-content-future-annotations and it fixes my issue in #9723. :+1:
@csbasil I rebased after you approved it.
Are there any plans on merging this PR?
There's an alternative to this on https://github.com/tiangolo/fastapi/pull/5860.
There's an alternative to this on https://github.com/tiangolo/fastapi/pull/5860.
Yes, I thought it's not necessary to get the actual type in this case, since None is a reserved word anyway.
It might be a bit faster to compare the string further up in the stack, but that's probably negligible.
There may be other arguments about using one over the other.