-
|
Minimal working example: from __future__ import annotations
import uvicorn
from fastapi import Depends, FastAPI
from starlette.requests import Request
app = FastAPI()
class Test():
def __call__(self, request: Request):
return 'test'
@app.get("/test/")
def test_call(test: str = Depends(Test())):
return {"test": test}
if __name__ == "__main__":
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True, debug=True)Description
Environment
Additional contextThe issue only happens when the FastAPI seems to have issues with |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 1 reply
-
|
Adding more information:
I'm not sure if the info that I've provided help us. EDIT [19/10/2022]: I really didn't know much about a lot of stuff at the time. 👀 |
Beta Was this translation helpful? Give feedback.
-
|
I'm running across this problem in Python 3.8 WITHOUT the |
Beta Was this translation helpful? Give feedback.
-
|
By marking the parameter type as Looked a little farther and both |
Beta Was this translation helpful? Give feedback.
-
|
I'm running into this problem too. It appears to be specific to objects used as dependencies via the Note that regular function dependencies work fine with |
Beta Was this translation helpful? Give feedback.
-
|
Bump on this thread, exact same issue as original poster. |
Beta Was this translation helpful? Give feedback.
-
|
You have may better luck raising this on the pydantic repository |
Beta Was this translation helpful? Give feedback.
-
|
This is still a problem, not sure why it's a discussion now. |
Beta Was this translation helpful? Give feedback.
-
|
I guess the following code can be found in pydantic: # pydantic/typing.py
if sys.version_info < (3, 9):
def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
return type_._evaluate(globalns, localns)
else:
def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
# Even though it is the right signature for python 3.9, mypy complains with
# `error: Too many arguments for "_evaluate" of "ForwardRef"` hence the cast...
return cast(Any, type_)._evaluate(globalns, localns, set())You'll notice that they are using internal methods of Users of FastAPI can workaround this annoyance by providing a Of course, instead of callings |
Beta Was this translation helpful? Give feedback.
-
|
PR that should address this issue: #11355 |
Beta Was this translation helpful? Give feedback.

PR that should address this issue: #11355