Skip to content

Commit fe0e46b

Browse files
authored
fix: correct working with dependencies versions (#1918)
* fix: correct working with dependencies versions * fix: correct FastAPI patch version check
1 parent bd188c7 commit fe0e46b

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

faststream/_compat.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
from importlib.metadata import version as get_version
55
from typing import Any, Callable, Dict, Mapping, Optional, Type, TypeVar, Union
66

7-
from fast_depends._compat import PYDANTIC_V2 as PYDANTIC_V2
8-
from fast_depends._compat import ( # type: ignore[attr-defined]
9-
PYDANTIC_VERSION as PYDANTIC_VERSION,
10-
)
117
from pydantic import BaseModel as BaseModel
8+
from pydantic.version import VERSION as PYDANTIC_VERSION
129

1310
from faststream.types import AnyDict
1411

@@ -57,23 +54,23 @@ def json_dumps(*a: Any, **kw: Any) -> bytes:
5754

5855
JsonSchemaValue = Mapping[str, Any]
5956

57+
major, minor, *_ = PYDANTIC_VERSION.split(".")
58+
_PYDANTCI_MAJOR, _PYDANTIC_MINOR = int(major), int(minor)
59+
60+
PYDANTIC_V2 = _PYDANTCI_MAJOR >= 2
61+
6062
if PYDANTIC_V2:
61-
if PYDANTIC_VERSION >= "2.4.0":
63+
if _PYDANTIC_MINOR >= 4:
6264
from pydantic.annotated_handlers import (
6365
GetJsonSchemaHandler as GetJsonSchemaHandler,
6466
)
6567
from pydantic_core.core_schema import (
6668
with_info_plain_validator_function as with_info_plain_validator_function,
6769
)
6870
else:
69-
if PYDANTIC_VERSION >= "2.10":
70-
from pydantic.annotated_handlers import (
71-
GetJsonSchemaHandler as GetJsonSchemaHandler,
72-
)
73-
else:
74-
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
75-
GetJsonSchemaHandler as GetJsonSchemaHandler,
76-
)
71+
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
72+
GetJsonSchemaHandler as GetJsonSchemaHandler,
73+
)
7774
from pydantic_core.core_schema import (
7875
general_plain_validator_function as with_info_plain_validator_function,
7976
)
@@ -155,8 +152,9 @@ def with_info_plain_validator_function( # type: ignore[misc]
155152
return {}
156153

157154

158-
anyio_major = int(get_version("anyio").split(".")[0])
159-
ANYIO_V3 = anyio_major == 3
155+
major, *_ = get_version("anyio").split(".")
156+
_ANYIO_MAJOR = int(major)
157+
ANYIO_V3 = _ANYIO_MAJOR == 3
160158

161159

162160
if ANYIO_V3:

faststream/broker/fastapi/_compat.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@
1212
from fastapi.dependencies.models import Dependant
1313
from fastapi.requests import Request
1414

15-
major, minor, patch, *_ = map(int, FASTAPI_VERSION.split("."))
16-
FASTAPI_V2 = major > 0 or minor > 100
17-
FASTAPI_V106 = major > 0 or minor >= 106
18-
FASTAPI_v102_3 = major > 0 or minor > 112 or (minor == 112 and patch > 2)
19-
FASTAPI_v102_4 = major > 0 or minor > 112 or (minor == 112 and patch > 3)
15+
major, minor, patch, *_ = FASTAPI_VERSION.split(".")
16+
17+
_FASTAPI_MAJOR, _FASTAPI_MINOR = int(major), int(minor)
18+
19+
FASTAPI_V2 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR > 100
20+
FASTAPI_V106 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR >= 106
21+
22+
try:
23+
_FASTAPI_PATCH = int(patch)
24+
except ValueError:
25+
FASTAPI_v102_3 = True
26+
FASTAPI_v102_4 = True
27+
else:
28+
FASTAPI_v102_3 = (
29+
_FASTAPI_MAJOR > 0
30+
or _FASTAPI_MINOR > 112
31+
or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 2)
32+
)
33+
FASTAPI_v102_4 = (
34+
_FASTAPI_MAJOR > 0
35+
or _FASTAPI_MINOR > 112
36+
or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 3)
37+
)
2038

2139
__all__ = (
2240
"create_response_field",

0 commit comments

Comments
 (0)