From e045bc124f68cd3e8fe3c14f2b39489fb5ee7aa1 Mon Sep 17 00:00:00 2001 From: leiserfg Date: Tue, 16 May 2023 10:19:07 +0200 Subject: [PATCH] Add check for pydantic 1.x as first step for suporting for 2.x --- uplink/converters/__init__.py | 2 +- .../converters/{pydantic_.py => pydantic_v1_.py} | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) rename uplink/converters/{pydantic_.py => pydantic_v1_.py} (94%) diff --git a/uplink/converters/__init__.py b/uplink/converters/__init__.py index ebc73b1c..e23e59f9 100644 --- a/uplink/converters/__init__.py +++ b/uplink/converters/__init__.py @@ -13,7 +13,7 @@ # fmt: off from uplink.converters.standard import StandardConverter from uplink.converters.marshmallow_ import MarshmallowConverter -from uplink.converters.pydantic_ import PydanticConverter +from uplink.converters.pydantic_v1_ import PydanticConverter from uplink.converters.typing_ import TypingConverter # fmt: on diff --git a/uplink/converters/pydantic_.py b/uplink/converters/pydantic_v1_.py similarity index 94% rename from uplink/converters/pydantic_.py rename to uplink/converters/pydantic_v1_.py index 4254ac9b..16b47720 100644 --- a/uplink/converters/pydantic_.py +++ b/uplink/converters/pydantic_v1_.py @@ -7,6 +7,16 @@ from uplink.converters.interfaces import Factory, Converter from uplink.utils import is_subclass +try: + from pydantic.version import VERSION + if not VERSION.startswith('1.'): + pydantic = None + else: + import pydantic + +except ImportError: # pragma: no cover + pydantic = None + def _encode_pydantic(obj): from pydantic.json import pydantic_encoder @@ -72,11 +82,7 @@ def get_users(self, username) -> List[UserModel]: $ pip install uplink[pydantic] """ - - try: - import pydantic - except ImportError: # pragma: no cover - pydantic = None + pydantic = pydantic def __init__(self): """