Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions fastapi/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ def __init__(
self.include_in_schema = include_in_schema
self.response_class = response_class

assert inspect.isfunction(endpoint) or inspect.ismethod(
endpoint
), f"An endpoint must be a function or method"
assert callable(endpoint), f"An endpoint must be a callable"
self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
for depends in self.dependencies[::-1]:
self.dependant.dependencies.insert(
Expand Down
24 changes: 24 additions & 0 deletions tests/test_callable_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from functools import partial

from fastapi import FastAPI
from starlette.testclient import TestClient


def main(some_arg, q: str = None):
return {"some_arg": some_arg, "q": q}


endpoint = partial(main, "foo")

app = FastAPI()

app.get("/")(endpoint)


client = TestClient(app)


def test_partial():
response = client.get("/?q=bar")
data = response.json()
assert data == {"some_arg": "foo", "q": "bar"}