pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.7 KiB
87 lines
3.7 KiB
# path: fastapi/_compat/__init__.py
|
|
|
|
"""
|
|
FastAPI Pydantic compatibility layer.
|
|
|
|
This module provides a v2-first compatibility layer that automatically
|
|
detects the Pydantic version and provides the appropriate symbols.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
# Import the v1 proxy module - this provides lazy loading and controlled warnings
|
|
# Don't import at module level to avoid warnings
|
|
|
|
# Import legacy compatibility symbols for backward compatibility
|
|
from .main import BaseConfig as BaseConfig
|
|
from .main import PydanticSchemaGenerationError as PydanticSchemaGenerationError
|
|
from .main import RequiredParam as RequiredParam
|
|
from .main import Undefined as Undefined
|
|
from .main import UndefinedType as UndefinedType
|
|
from .main import Url as Url
|
|
from .main import Validator as Validator
|
|
from .main import _get_model_config as _get_model_config
|
|
from .main import _is_error_wrapper as _is_error_wrapper
|
|
from .main import _is_model_class as _is_model_class
|
|
from .main import _is_model_field as _is_model_field
|
|
from .main import _is_undefined as _is_undefined
|
|
from .main import _model_dump as _model_dump
|
|
from .main import _model_rebuild as _model_rebuild
|
|
from .main import copy_field_info as copy_field_info
|
|
from .main import create_body_model as create_body_model
|
|
from .main import evaluate_forwardref as evaluate_forwardref
|
|
from .main import get_annotation_from_field_info as get_annotation_from_field_info
|
|
from .main import get_cached_model_fields as get_cached_model_fields
|
|
from .main import get_compat_model_name_map as get_compat_model_name_map
|
|
from .main import get_definitions as get_definitions
|
|
from .main import get_missing_field_error as get_missing_field_error
|
|
from .main import get_schema_from_model_field as get_schema_from_model_field
|
|
from .main import is_bytes_field as is_bytes_field
|
|
from .main import is_bytes_sequence_field as is_bytes_sequence_field
|
|
from .main import is_scalar_field as is_scalar_field
|
|
from .main import is_scalar_sequence_field as is_scalar_sequence_field
|
|
from .main import is_sequence_field as is_sequence_field
|
|
from .main import serialize_sequence_value as serialize_sequence_value
|
|
from .main import (
|
|
with_info_plain_validator_function as with_info_plain_validator_function,
|
|
)
|
|
from .model_field import ModelField as ModelField
|
|
from .shared import PYDANTIC_V2 as PYDANTIC_V2
|
|
from .shared import PYDANTIC_VERSION_MINOR_TUPLE as PYDANTIC_VERSION_MINOR_TUPLE
|
|
from .shared import annotation_is_pydantic_v1 as annotation_is_pydantic_v1
|
|
from .shared import field_annotation_is_scalar as field_annotation_is_scalar
|
|
from .shared import (
|
|
is_uploadfile_or_nonable_uploadfile_annotation as is_uploadfile_or_nonable_uploadfile_annotation,
|
|
)
|
|
from .shared import (
|
|
is_uploadfile_sequence_annotation as is_uploadfile_sequence_annotation,
|
|
)
|
|
from .shared import lenient_issubclass as lenient_issubclass
|
|
from .shared import sequence_types as sequence_types
|
|
from .shared import value_is_sequence as value_is_sequence
|
|
|
|
# V1 symbols are available via the v1 proxy module
|
|
# Access them directly: from fastapi._compat import v1; v1.CoreSchema
|
|
# This avoids import-time access and warnings
|
|
|
|
# Export V1 symbols as Any to avoid import-time access
|
|
CoreSchema = Any
|
|
GetJsonSchemaHandler = Any
|
|
JsonSchemaValue = dict[str, Any]
|
|
|
|
def _normalize_errors(errors):
|
|
from importlib import import_module
|
|
v1 = import_module("fastapi._compat.v1") # proxy lazy
|
|
return v1._normalize_errors(errors)
|
|
|
|
# Make v1 available as an attribute
|
|
def __getattr__(name: str):
|
|
if name == "v1":
|
|
# Import directly to avoid recursion
|
|
import importlib
|
|
return importlib.import_module("fastapi._compat.v1")
|
|
raise AttributeError(f"module 'fastapi._compat' has no attribute '{name}'")
|
|
|
|
# No __all__ defined - exports everything implicitly for backward compatibility
|