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

✨ Import and re-export data structures from Starlette, used by Request properties, on fastapi.datastructures #1872

Merged

Conversation

jamescurtin
Copy link
Contributor

Closes #1871

@codecov
Copy link

codecov bot commented Aug 10, 2020

Codecov Report

Merging #1872 (3866e3d) into master (6c80e9a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1872   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          401       401           
  Lines        10080     10095   +15     
=========================================
+ Hits         10080     10095   +15     
Impacted Files Coverage Δ
fastapi/datastructures.py 100.00% <100.00%> (ø)
fastapi/applications.py 100.00% <0.00%> (ø)
fastapi/openapi/utils.py 100.00% <0.00%> (ø)
docs_src/metadata/tutorial001.py 100.00% <0.00%> (ø)
...ts/test_tutorial/test_metadata/test_tutorial001.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c80e9a...3866e3d. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit f5e665f at: https://5f31637f500fdecfd2a38cf2--fastapi.netlify.app

@SirTelemak
Copy link

Why not import it in fastapi.datastructures for more compatible syntax? Imo it's unintuitive that starlette.datastructures models imported from fastapi.requests.
Moreover in your example:

def example_get_url_from_request(request: Request) -> URL:

there URL is not request, it's response which, again, unintuitive in my opinion.

@jamescurtin
Copy link
Contributor Author

Why not import it in fastapi.datastructures for more compatible syntax? Imo it's unintuitive that starlette.datastructures models imported from fastapi.requests.

Good point; restructured such that the imports mirror the structure of starlette

Copy link
Sponsor Collaborator

@Kludex Kludex left a 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.

@@ -1,5 +1,11 @@
from typing import Any, Callable, Iterable, Type

from starlette.datastructures import URL # noqa: F401
Copy link
Sponsor Collaborator

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:

Suggested change
from starlette.datastructures import URL # noqa: F401
from starlette.datastructures import (
Address,
FormData,
Headers,
QueryParams,
State,
UploadFile as StarletteUploadFile,
URL
)

Copy link
Contributor Author

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.

@@ -1,7 +1,6 @@
"""FastAPI framework, high performance, easy to learn, fast to code, ready for production"""

__version__ = "0.61.0"

Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readd this line, please

Copy link
Contributor Author

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
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated?

Copy link
Contributor Author

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)

@github-actions
Copy link
Contributor

📝 Docs preview for commit bf8e816 at: https://5f3298c76d5d9fb790e318dc--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit 2202dc6 at: https://5f32a720f8bd09a98ec04244--fastapi.netlify.app

@jamescurtin
Copy link
Contributor Author

👋 Checking in on this PR: would someone please be able to review? Thank you!

@github-actions
Copy link
Contributor

📝 Docs preview for commit 3866e3d at: https://6102c8fb4d4db930370e63f7--fastapi.netlify.app

@tiangolo
Copy link
Owner

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 0.68.0 🔖🎉

@tiangolo tiangolo changed the title Import types used by Request properties ✨ Import and re-export data structures from Starlette, used by Request properties, on fastapi.datastructures Jul 29, 2021
@tiangolo tiangolo merged commit 4eada92 into tiangolo:master Jul 29, 2021
solomein-sv pushed a commit to solomein-sv/fastapi that referenced this pull request Jul 30, 2021
…t properties, on `fastapi.datastructures` (tiangolo#1872)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add imports of Starlette datastructures for type annotating Request
4 participants