diff --git a/faststream/_compat.py b/faststream/_compat.py index b23013f4bd..6cbb5b4b89 100644 --- a/faststream/_compat.py +++ b/faststream/_compat.py @@ -4,11 +4,8 @@ from importlib.metadata import version as get_version from typing import Any, Callable, Dict, Mapping, Optional, Type, TypeVar, Union -from fast_depends._compat import PYDANTIC_V2 as PYDANTIC_V2 -from fast_depends._compat import ( # type: ignore[attr-defined] - PYDANTIC_VERSION as PYDANTIC_VERSION, -) from pydantic import BaseModel as BaseModel +from pydantic.version import VERSION as PYDANTIC_VERSION from faststream.types import AnyDict @@ -57,8 +54,13 @@ def json_dumps(*a: Any, **kw: Any) -> bytes: JsonSchemaValue = Mapping[str, Any] +major, minor, *_ = PYDANTIC_VERSION.split(".") +_PYDANTCI_MAJOR, _PYDANTIC_MINOR = int(major), int(minor) + +PYDANTIC_V2 = _PYDANTCI_MAJOR >= 2 + if PYDANTIC_V2: - if PYDANTIC_VERSION >= "2.4.0": + if _PYDANTIC_MINOR >= 4: from pydantic.annotated_handlers import ( GetJsonSchemaHandler as GetJsonSchemaHandler, ) @@ -66,14 +68,9 @@ def json_dumps(*a: Any, **kw: Any) -> bytes: with_info_plain_validator_function as with_info_plain_validator_function, ) else: - if PYDANTIC_VERSION >= "2.10": - from pydantic.annotated_handlers import ( - GetJsonSchemaHandler as GetJsonSchemaHandler, - ) - else: - from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef] - GetJsonSchemaHandler as GetJsonSchemaHandler, - ) + from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef] + GetJsonSchemaHandler as GetJsonSchemaHandler, + ) from pydantic_core.core_schema import ( general_plain_validator_function as with_info_plain_validator_function, ) @@ -155,8 +152,9 @@ def with_info_plain_validator_function( # type: ignore[misc] return {} -anyio_major = int(get_version("anyio").split(".")[0]) -ANYIO_V3 = anyio_major == 3 +major, *_ = get_version("anyio").split(".") +_ANYIO_MAJOR = int(major) +ANYIO_V3 = _ANYIO_MAJOR == 3 if ANYIO_V3: diff --git a/faststream/broker/fastapi/_compat.py b/faststream/broker/fastapi/_compat.py index 206aff52ef..e99c199ae1 100644 --- a/faststream/broker/fastapi/_compat.py +++ b/faststream/broker/fastapi/_compat.py @@ -12,11 +12,29 @@ from fastapi.dependencies.models import Dependant from fastapi.requests import Request -major, minor, patch, *_ = map(int, FASTAPI_VERSION.split(".")) -FASTAPI_V2 = major > 0 or minor > 100 -FASTAPI_V106 = major > 0 or minor >= 106 -FASTAPI_v102_3 = major > 0 or minor > 112 or (minor == 112 and patch > 2) -FASTAPI_v102_4 = major > 0 or minor > 112 or (minor == 112 and patch > 3) +major, minor, patch, *_ = FASTAPI_VERSION.split(".") + +_FASTAPI_MAJOR, _FASTAPI_MINOR = int(major), int(minor) + +FASTAPI_V2 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR > 100 +FASTAPI_V106 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR >= 106 + +try: + _FASTAPI_PATCH = int(patch) +except ValueError: + FASTAPI_v102_3 = True + FASTAPI_v102_4 = True +else: + FASTAPI_v102_3 = ( + _FASTAPI_MAJOR > 0 + or _FASTAPI_MINOR > 112 + or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 2) + ) + FASTAPI_v102_4 = ( + _FASTAPI_MAJOR > 0 + or _FASTAPI_MINOR > 112 + or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 3) + ) __all__ = ( "create_response_field",