Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Allow None as return type for bodiless responses #9425

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hofrob
Copy link

@hofrob hofrob commented Apr 21, 2023

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.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 243f74a at: https://6442a49fa75498079da29ef3--fastapi.netlify.app

@hofrob hofrob force-pushed the fix-return-no-content-future-annotations branch from 243f74a to bb5ef4a Compare June 6, 2023 13:21
@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

📝 Docs preview for commit bb5ef4a at: https://647f33cb7357732441e2ff02--fastapi.netlify.app

@fnep
Copy link

fnep commented Jun 24, 2023

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. 👍

@hofrob
Copy link
Author

hofrob commented Jul 18, 2023

@csbasil I rebased after you approved it.

Are there any plans on merging this PR?

@Kludex Kludex changed the title fix: allow None as return type for http 204 🐛 Allow None as return type for bodiless responses Jul 18, 2023
@Kludex
Copy link
Sponsor Collaborator

Kludex commented Jul 18, 2023

There's an alternative to this on #5860.

@hofrob
Copy link
Author

hofrob commented Jul 18, 2023

There's an alternative to this on #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.

@tiangolo tiangolo changed the title 🐛 Allow None as return type for bodiless responses ✨ Allow None as return type for bodiless responses Jan 9, 2024
@tiangolo tiangolo added the feature New feature or request label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using PEP 649 annotations with status code 204 No Content and return type None raises AssertionError
5 participants