From af95dea001dea0625728084a2b3ece2e80cecb14 Mon Sep 17 00:00:00 2001 From: faph Date: Mon, 29 Jul 2024 16:57:23 +0100 Subject: [PATCH] Avoid deprecated Pydantic __fields__ attribute --- src/py_avro_schema/_schemas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/py_avro_schema/_schemas.py b/src/py_avro_schema/_schemas.py index d63e1c0..3e44234 100644 --- a/src/py_avro_schema/_schemas.py +++ b/src/py_avro_schema/_schemas.py @@ -914,7 +914,7 @@ class PydanticSchema(RecordSchema): def handles_type(cls, py_type: Type) -> bool: """Whether this schema class can represent a given Python class""" py_type = _type_from_annotated(py_type) - return hasattr(py_type, "__fields__") + return hasattr(py_type, "__pydantic_private__") def __init__(self, py_type: Type[pydantic.BaseModel], namespace: Optional[str] = None, options: Option = Option(0)): """ @@ -973,7 +973,7 @@ def handles_type(cls, py_type: Type) -> bool: # Dataclasses are handled above not dataclasses.is_dataclass(py_type) # Pydantic models are handled above - and not hasattr(py_type, "__fields__") + and not hasattr(py_type, "__pydantic_private__") # If we are subclassing a string, used the "named string" approach and (inspect.isclass(py_type) and not issubclass(py_type, str)) # Any other class with __init__ with typed args