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

Add most used objects to __init__.py #2668

Closed
wants to merge 1 commit into from
Closed

Conversation

Kludex
Copy link
Sponsor Member

@Kludex Kludex commented Aug 12, 2024

@tomchristie Is there a reason for not doing this?

@tomchristie
Copy link
Member

Held back on that as wanted to encourage a consistent import style, the concise imports are nice tho. 👍

"Mount",
"WebSocketRoute",
"WebSocket",
)
Copy link
Member

@tomchristie tomchristie Aug 12, 2024

Choose a reason for hiding this comment

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

Reviewing the complete set of documented imports here's what I've got...

from starlette.applications import Starlette
from starlette.authentication import requires, AuthCredentials, AuthenticationBackend, AuthenticationError, SimpleUser
from starlette.background import BackgroundTask
from starlette.config import environ, Config
from starlette.datastructures import Headers, MutableHeaders, Secret, URL
from starlette.endpoints import HTTPEndpoint
from starlette.exceptions import HTTPException, WebSocketException
from starlette.middleware import Middleware
from starlette.responses import Response, FileResponse, HTMLResponse, JSONResponse, PlainTextResponse, RedirectResponse, StreamingResponse
from starlette.requests import Request
from starlette.routing import Route, Mount, WebSocketRoute
from starlette.schemas import SchemaGenerator
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates
from starlette.testclient import TestClient
from starlette.websockets import WebSocket

from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.cors import CORSMiddleware
from starlette.middleware.gzip import GZipMiddleware
from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware
from starlette.middleware.sessions import SessionMiddleware
from starlette.middleware.trustedhost import TrustedHostMiddleware

Does it make sense to include the whole set of imports here, or just the subset above?

Copy link
Member

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

The only con of this is that it increases import time for cases where you only use a subset of the types/features which I feel like goes against Starlette's positioning as a toolking as opposed to a framework.

@Kludex
Copy link
Sponsor Member Author

Kludex commented Aug 12, 2024

The only con of this is that it increases import time for cases where you only use a subset of the types/features which I feel like goes against Starlette's positioning as a toolking as opposed to a framework.

That's a good point.

@Kludex Kludex closed this Aug 12, 2024
@Kludex Kludex deleted the add-structures-to-init branch August 12, 2024 13:32
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.

3 participants