-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
docs: move internal code-blocks
to docs/examples/**/*.py
files to be automatically tested
#3445
base: main
Are you sure you want to change the base?
Conversation
…ing missing init files
…s folder + fix typo in cli/plugin.py example
… and adding language python to missing blocks
…missing __init__ files
… code to examples folder
code-blocks
to docs/examples/**/*.py
files to be automatically tested
Still remaining @Kumzy we just need to fix any pre-commit failures
and fix the ones in the new Basically most of them look like missing imports like
Details
and any test failures that this has exposed
|
@litestar-org/maintainers when we have examples like this, how do we want to handle the moving of them? Should we create
from os import environ
from my_app.guards import secret_token_guard
from litestar import get
@get(path="/secret", guards=[secret_token_guard], opt={"secret": environ.get("SECRET")})
def secret_endpoint() -> None: ... |
Examples should all be self-contained. There are rare exceptions (like templates / static files), but this isn't one of them; The guard could very well be defined in the same file. Having an app for every code example also give the benefit of us being able to auto-run them which, even if the example isn't tested explicitly, at least implicitly ensures that we don't have broken examples. |
Had some question regarding latest changes to add import:
subscriber = await channels.subscribe(["foo", "bar"])
try:
... # do some stuff here
finally:
await channels.unsubscribe(subscriber)
from litestar import Litestar
app = Litestar(lifespan=[ctx_a, ctx_b], on_shutdown=[hook_a, hook_b])
@get(path="/form")
def get_form(request: HTMXRequest) -> Template:
htmx = request.htmx # if true will return HTMXDetails class object
if htmx:
print(htmx.current_url)
# OR
if request.htmx:
print(request.htmx.current_url)
return HTMXTemplate(template_name="partial.html", context=context, push_url="/form")
from litestar import WebSocket, websocket
from litestar.types.asgi_types import WebSocketMode
mode = WebSocketMode("text")
@websocket("/")
async def handler(socket: WebSocket) -> None:
await socket.accept()
async for message in socket.iter_data(mode):
await socket.send_msgpack(message) |
Description
Authored by @Kumzy in #3392, moved here due to fork issues
Closes
#3362