-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
✨ Import and re-export data structures from Starlette, used by Request properties, on fastapi.datastructures
#1872
✨ Import and re-export data structures from Starlette, used by Request properties, on fastapi.datastructures
#1872
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1872 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 401 401
Lines 10080 10095 +15
=========================================
+ Hits 10080 10095 +15
Continue to review full report at Codecov.
|
📝 Docs preview for commit f5e665f at: https://5f31637f500fdecfd2a38cf2--fastapi.netlify.app |
Why not import it in fastapi.datastructures for more compatible syntax? Imo it's unintuitive that starlette.datastructures models imported from fastapi.requests. def example_get_url_from_request(request: Request) -> URL: there URL is not request, it's response which, again, unintuitive in my opinion. |
Good point; restructured such that the imports mirror the structure of starlette |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestions are only focused on the syntax. I'm not sure about the idea of the changes tho. I saw the issue about this, but I'm still not sure.
fastapi/datastructures.py
Outdated
@@ -1,5 +1,11 @@ | |||
from typing import Any, Callable, Iterable, Type | |||
|
|||
from starlette.datastructures import URL # noqa: F401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to create a multiline suggestion, but:
from starlette.datastructures import URL # noqa: F401 | |
from starlette.datastructures import ( | |
Address, | |
FormData, | |
Headers, | |
QueryParams, | |
State, | |
UploadFile as StarletteUploadFile, | |
URL | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I would agree, but the change you suggest is incompatible with the bash scripts/format-imports.sh
script.
That script invokes isort fastapi tests docs_src scripts --force-single-line-imports
, which splits each import to a single line, but does not propagate the noqa
hint to each line. It then invokes autoflake --remove-all-unused-imports ...
which deletes the imports.
fastapi/__init__.py
Outdated
@@ -1,7 +1,6 @@ | |||
"""FastAPI framework, high performance, easy to learn, fast to code, ready for production""" | |||
|
|||
__version__ = "0.61.0" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readd this line, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff was generated by running bash scripts/format-imports.sh
. I just confirmed by re-adding it and running the format script; it removes the line again.
fastapi/types.py
Outdated
@@ -0,0 +1 @@ | |||
from starlette.types import Receive # noqa: F401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes--thank you! (Though it was actually the one in fastapi/requests.py
that was repeated)
📝 Docs preview for commit bf8e816 at: https://5f3298c76d5d9fb790e318dc--fastapi.netlify.app |
📝 Docs preview for commit 2202dc6 at: https://5f32a720f8bd09a98ec04244--fastapi.netlify.app |
👋 Checking in on this PR: would someone please be able to review? Thank you! |
📝 Docs preview for commit 3866e3d at: https://6102c8fb4d4db930370e63f7--fastapi.netlify.app |
Great, thanks @jamescurtin for your contribution! 🚀 Thanks @Kludex and @SirTelemak for the discussion! I updated it a bit to keep the current import style that improves typing support in editors (e.g. autoimports). This will be available later today in FastAPI version |
fastapi.datastructures
…t properties, on `fastapi.datastructures` (tiangolo#1872) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Closes #1871