mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-19 05:53:12 -04:00
⬆ Add support for Python 3.9 (#2298)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e9ba01dc59
commit
ab33ba27af
24
tests/test_typing_python39.py
Normal file
24
tests/test_typing_python39.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from .utils import needs_py39
|
||||
|
||||
|
||||
@needs_py39
|
||||
def test_typing():
|
||||
types = {
|
||||
list[int]: [1, 2, 3],
|
||||
dict[str, list[int]]: {"a": [1, 2, 3], "b": [4, 5, 6]},
|
||||
set[int]: [1, 2, 3], # `set` is converted to `list`
|
||||
tuple[int, ...]: [1, 2, 3], # `tuple` is converted to `list`
|
||||
}
|
||||
for test_type, expect in types.items():
|
||||
app = FastAPI()
|
||||
|
||||
@app.post("/", response_model=test_type)
|
||||
def post_endpoint(input: test_type):
|
||||
return input
|
||||
|
||||
res = TestClient(app).post("/", json=expect)
|
||||
assert res.status_code == 200, res.json()
|
||||
assert res.json() == expect
|
||||
Reference in New Issue
Block a user