-
First Check
Commit to Help
Example Codefrom typing import Annotated, TypeVar
from fastapi import FastAPI, Depends
app = FastAPI()
T = TypeVar("T")
Inject = Annotated[T, Depends()]
class FirstService:
pass
class SecondService:
pass
@app.get("/first")
async def first_service(service: Inject[FirstService]):
pass
@app.get("/second")
async def second_service(service: Inject[SecondService]):
pass
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) DescriptionWhen using TypeVar, dependencies are injected incorrectly. Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.95.1 Python VersionPython 3.11.1 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
nzig
May 2, 2023
Replies: 1 comment 1 reply
-
Interesting use-case. This appears to be a bug. I've opened #9479 to fix it. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
9en9i
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting use-case.
This appears to be a bug. I've opened #9479 to fix it.