-
First Check
Commit to Help
Example Codefrom typing import TYPE_CHECKING
from fastapi import FastAPI, Depends
if TYPE_CHECKING:
class Foo: ...
app = FastAPI()
def get_foo() -> Foo | None:
return None
@app.get("/")
def read_root(foo: Foo | None = Depends(get_foo)):
return {"Hello": "World"}Descriptionrun From my own analysis it could come from Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.128.0 Pydantic Version2.12.5 Python VersionPython 3.14.2 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
from __future__ import annotations
from typing import TYPE_CHECKING
from fastapi import FastAPI, Depends
if TYPE_CHECKING:
class Foo: ...
app = FastAPI()
def get_foo() -> Foo | None:
return None
@app.get("/")
def read_root(foo: Foo | None = Depends(get_foo)):
return {"Hello": "World"}The issue occurs because Using |
Beta Was this translation helpful? Give feedback.
-
|
I would recommend not to use |
Beta Was this translation helpful? Give feedback.
-
I think this might work. Just tried this and it doesn't break any test, and even fixes one marked with |
Beta Was this translation helpful? Give feedback.
#14789