Browse Source

As pydantic v1 support is dropped, we can "inline" the color encoder

pull/13803/head
Pedro Lobato 5 months ago
parent
commit
d7a6788230
  1. 10
      fastapi/encoders.py

10
fastapi/encoders.py

@ -33,18 +33,16 @@ from pydantic.networks import AnyUrl, NameEmail
from pydantic.types import SecretBytes, SecretStr
from pydantic_core import PydanticUndefinedType
# Dropped support for Pydantic v1 so we can remove the try-except import and the related code
from pydantic_extra_types import color as et_color
from ._compat import (
Url,
is_pydantic_v1_model_instance,
)
encoders_by_extra_type: dict[type[Any], Callable[[Any], Any]] = {}
try:
from pydantic_extra_types import color as et_color
encoders_by_extra_type: dict[type[Any], Callable[[Any], Any]] = {et_color.Color: str}
encoders_by_extra_type[et_color.Color] = str
except ImportError:
pass
try:
from pydantic_extra_types import coordinate

Loading…
Cancel
Save