Browse Source

Refactor import statements in utils for compatibility with Pydantic V2

pull/14446/head
g7azazlo 8 months ago
parent
commit
b31dd81f48
  1. 4
      fastapi/utils.py

4
fastapi/utils.py

@ -314,7 +314,7 @@ def _infer_type_from_ast(
if PYDANTIC_V2: if PYDANTIC_V2:
from pydantic import create_model from pydantic import create_model
else: else:
from pydantic import create_model from fastapi._compat.v1 import create_model
return create_model(f"Model_{context_name}", **fields) # type: ignore[call-overload] return create_model(f"Model_{context_name}", **fields) # type: ignore[call-overload]
@ -448,7 +448,7 @@ def infer_response_model_from_ast(
if PYDANTIC_V2: if PYDANTIC_V2:
from pydantic import create_model from pydantic import create_model
else: else:
from pydantic import create_model from fastapi._compat.v1 import create_model
model_name = f"ResponseModel_{endpoint_function.__name__}" model_name = f"ResponseModel_{endpoint_function.__name__}"
try: try:

Loading…
Cancel
Save