Skip to content

Commit

Permalink
Pydantiv2.4.0 compat (#738)
Browse files Browse the repository at this point in the history
* docs: fix GH README

* fix: pydantic2.4.0 compatibility

* chore: bump version

* lint: fix pydantic styles
  • Loading branch information
Lancetnik authored Sep 25, 2023
1 parent dcca20a commit b8f63bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion faststream/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Simple and fast framework to create message brokers based microservices"""
__version__ = "0.1.1"
__version__ = "0.1.2"


INSTALL_YAML = """
Expand Down
7 changes: 4 additions & 3 deletions faststream/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ def raise_fastapi_validation_error(errors: List[Any], body: AnyDict) -> Never:

if PYDANTIC_V2:
from pydantic import ConfigDict as ConfigDict
from pydantic._internal._annotated_handlers import (
from pydantic.annotated_handlers import (
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
from pydantic_core import CoreSchema as CoreSchema
from pydantic_core import to_jsonable_python
from pydantic_core.core_schema import (
general_plain_validator_function as general_plain_validator_function,
with_info_plain_validator_function as with_info_plain_validator_function,
)

SCHEMA_FIELD = "json_schema_extra"
Expand Down Expand Up @@ -168,7 +168,8 @@ def model_to_jsonable(
def model_copy(model: ModelVar, **kwargs: Any) -> ModelVar:
return model.copy(**kwargs)

def general_plain_validator_function( # type: ignore[misc]
# TODO: pydantic types misc
def with_info_plain_validator_function( # type: ignore[misc]
function: Callable[..., Any],
*,
ref: Optional[str] = None,
Expand Down
4 changes: 2 additions & 2 deletions faststream/asyncapi/schema/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
JsonSchemaValue,
Required,
TypedDict,
general_plain_validator_function,
with_info_plain_validator_function,
is_installed,
)
from faststream.log import logger
Expand Down Expand Up @@ -54,7 +54,7 @@ def __get_pydantic_core_schema__(
source: Type[Any],
handler: Callable[[Any], CoreSchema],
) -> JsonSchemaValue:
return general_plain_validator_function(cls._validate)
return with_info_plain_validator_function(cls._validate)


class ContactDict(TypedDict, total=False):
Expand Down
10 changes: 6 additions & 4 deletions faststream/asyncapi/schema/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from faststream._compat import PYDANTIC_V2
from faststream.asyncapi.schema.utils import (
ExternalDocs,
ExternalDocsDict,
Tag,
TagDict,
)


Expand Down Expand Up @@ -72,8 +70,12 @@ class Message(BaseModel):
# examples
# traits

tags: Optional[List[Union[Tag, TagDict, Dict[str, Any]]]] = None
externalDocs: Optional[Union[ExternalDocs, ExternalDocsDict, Dict[str, Any]]] = None
tags: Optional[
List[Union[Tag, Dict[str, Any]]]
] = None # TODO: weird TagDict behavior
externalDocs: Optional[
Union[ExternalDocs, Dict[str, Any]]
] = None # TODO: weird ExternalDocsDict behavior

if PYDANTIC_V2:
model_config = {"extra": "allow"}
Expand Down

0 comments on commit b8f63bc

Please sign in to comment.