mirror of https://github.com/tiangolo/fastapi.git
make compatible with Python <3.10 and Pydantic v1
Signed-off-by: merlinz01 <158784988+merlinz01@users.noreply.github.com>
This commit is contained in:
parent
826f11a611
commit
6d1617df7f
|
|
@ -733,11 +733,23 @@ async def solve_dependencies(
|
|||
)
|
||||
|
||||
|
||||
def _allows_none(field: ModelField) -> bool:
|
||||
origin = get_origin(field.type_)
|
||||
return (origin is Union or origin is types.UnionType) and type(None) in get_args(
|
||||
field.type_
|
||||
)
|
||||
if PYDANTIC_V2:
|
||||
if sys.hexversion >= 0x30A00000:
|
||||
|
||||
def _allows_none(field: ModelField) -> bool:
|
||||
origin = get_origin(field.type_)
|
||||
return (origin is Union or origin is types.UnionType) and type(
|
||||
None
|
||||
) in get_args(field.type_)
|
||||
else:
|
||||
|
||||
def _allows_none(field: ModelField) -> bool:
|
||||
origin = get_origin(field.type_)
|
||||
return origin is Union and type(None) in get_args(field.type_)
|
||||
else:
|
||||
|
||||
def _allows_none(field: ModelField) -> bool:
|
||||
return field.allow_none
|
||||
|
||||
|
||||
def _validate_value_with_model_field(
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ DEFAULT = 1234567890
|
|||
|
||||
endpoints = []
|
||||
|
||||
if sys.hexversion >= 0x31000000:
|
||||
if sys.hexversion >= 0x30A0000:
|
||||
from typing import Annotated
|
||||
|
||||
@app.post("/api1")
|
||||
|
|
@ -22,7 +22,7 @@ if sys.hexversion >= 0x31000000:
|
|||
endpoints.append("/api1")
|
||||
|
||||
|
||||
if sys.hexversion >= 0x30900000:
|
||||
if sys.hexversion >= 0x3090000:
|
||||
from typing import Annotated
|
||||
|
||||
@app.post("/api2")
|
||||
|
|
|
|||
Loading…
Reference in New Issue