Coverage for tests / test_wrapped_method_forward_reference.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1import functools 1efgh
3from fastapi import FastAPI 1efgh
4from fastapi.testclient import TestClient 1efgh
6from .forward_reference_type import forwardref_method 1efgh
9def passthrough(f): 1efgh
10 @functools.wraps(f) 1abcd
11 def method(*args, **kwargs): 1abcd
12 return f(*args, **kwargs) 1abcd
14 return method 1abcd
17def test_wrapped_method_type_inference(): 1efgh
18 """
19 Regression test ensuring that when a method imported from another module
20 is decorated with something that sets the __wrapped__ attribute (functools.wraps),
21 then the types are still processed correctly, including dereferencing of forward
22 references.
23 """
24 app = FastAPI() 1abcd
25 client = TestClient(app) 1abcd
26 app.post("/endpoint")(passthrough(forwardref_method)) 1abcd
27 app.post("/endpoint2")(passthrough(passthrough(forwardref_method))) 1abcd
28 with client: 1abcd
29 response = client.post("/endpoint", json={"input": {"x": 0}}) 1abcd
30 response2 = client.post("/endpoint2", json={"input": {"x": 0}}) 1abcd
31 assert response.json() == response2.json() == {"x": 1} 1abcd