Allow using Pydantic v2 (#533)

Co-authored-by: Chayim <chayim@users.noreply.github.com>
This commit is contained in:
Manabu Niseki 2023-07-12 17:48:08 +09:00 committed by GitHub
parent 323787151e
commit 3a0fa0c7be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 14 deletions

19
aredis_om/_compat.py Normal file
View file

@ -0,0 +1,19 @@
from pydantic.version import VERSION as PYDANTIC_VERSION
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
if PYDANTIC_V2:
from pydantic.v1 import BaseModel, validator
from pydantic.v1.fields import FieldInfo, ModelField, Undefined, UndefinedType
from pydantic.v1.json import ENCODERS_BY_TYPE
from pydantic.v1.main import ModelMetaclass, validate_model
from pydantic.v1.typing import NoArgAnyCallable
from pydantic.v1.utils import Representation
else:
from pydantic import BaseModel, validator
from pydantic.fields import FieldInfo, ModelField, Undefined, UndefinedType
from pydantic.json import ENCODERS_BY_TYPE
from pydantic.main import ModelMetaclass, validate_model
from pydantic.typing import NoArgAnyCallable
from pydantic.utils import Representation

View file

@ -31,8 +31,7 @@ from pathlib import PurePath
from types import GeneratorType
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
from pydantic import BaseModel
from pydantic.json import ENCODERS_BY_TYPE
from .._compat import ENCODERS_BY_TYPE, BaseModel
SetIntStr = Set[Union[int, str]]

View file

@ -25,18 +25,24 @@ from typing import (
)
from more_itertools import ichunked
from pydantic import BaseModel, validator
from pydantic.fields import FieldInfo as PydanticFieldInfo
from pydantic.fields import ModelField, Undefined, UndefinedType
from pydantic.main import ModelMetaclass, validate_model
from pydantic.typing import NoArgAnyCallable
from pydantic.utils import Representation
from redis.commands.json.path import Path
from redis.exceptions import ResponseError
from typing_extensions import Protocol, get_args, get_origin
from ulid import ULID
from .. import redis
from .._compat import BaseModel
from .._compat import FieldInfo as PydanticFieldInfo
from .._compat import (
ModelField,
ModelMetaclass,
NoArgAnyCallable,
Representation,
Undefined,
UndefinedType,
validate_model,
validator,
)
from ..checks import has_redis_json, has_redisearch
from ..connections import get_redis_connection
from ..util import ASYNC_MODE