Here's a self-contained minimal, reproducible, example with my use case:
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/")
def read_root(q: str = Query(None)):
return {"q": q.lower()}
q can be None and that q.lower() could raise an error.I would like the examples in the docs to use Optional:
from typing import Optional
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/")
def read_root(q: Optional[str] = Query(None)):
return {"q": q.lower()}
By using Optional the editor would be able to warn that q.lower() could raise an error if q is None.
To leave it as is.
To know the FastAPI version use:
python -c "import fastapi; print(fastapi.__version__)"
To know the Python version use:
python --version
I was waiting to first introduce Optional in the docs, but it was done in https://github.com/tiangolo/fastapi/pull/1377 :tada:
The new docs are here: https://fastapi.tiangolo.com/python-types/#optional
Now it's a good moment to update all the examples that have a default of None in all the docs to also use Optional.
I'll be working on this with @chrisngyn and @YKo20010
I believe this was already solved with #1644 being merged to master. Should this issue be closed @tiangolo?
Thanks a lot!
@tiangolo
Is this issue still accepting contributors?
You mentioned here that you merged another branch.
@tiangolo Is this available to take up?
@tiangolo is this fixed or do you want someone to take it up a quick search through the docs makes it look all solved?
This issue was solved on https://github.com/tiangolo/fastapi/pull/1644
To confirm I've made a quick search and the docs are following the request on this issue. :nerd_face:
Most helpful comment
I'll be working on this with @chrisngyn and @YKo20010