Skip to content

Commit

Permalink
Add model_field and model_rebuild to v1 pydantic compat layer
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 18, 2023
1 parent 92a5351 commit 45d95e6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions python/lsst/daf/butler/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import TYPE_CHECKING, Any

from pydantic import BaseModel
from pydantic.fields import FieldInfo
from pydantic.version import VERSION as PYDANTIC_VERSION

if sys.version_info >= (3, 11, 0):
Expand Down Expand Up @@ -119,6 +120,21 @@ def model_dump_json(
) -> str:
return ""

@property
def model_fields(self) -> dict[str, FieldInfo]: # type: ignore
return {}

@classmethod
def model_rebuild(
cls,
*,
force: bool = False,
raise_errors: bool = True,
_parent_namespace_depth: int = 2,
_types_namespace: dict[str, Any] | None = None,
) -> bool | None:
return None

else:

class _BaseModelCompat(BaseModel): # type:ignore[no-redef]
Expand Down Expand Up @@ -160,3 +176,18 @@ def model_dump_json(
@classmethod # type: ignore
def model_construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self:
return cls.construct(_fields_set=_fields_set, **values)

@property
def model_fields(self) -> dict[str, FieldInfo]: # type: ignore
return self.__fields__ # type: ignore

@classmethod
def model_rebuild(
cls,
*,
force: bool = False,
raise_errors: bool = True,
_parent_namespace_depth: int = 2,
_types_namespace: dict[str, Any] | None = None,
) -> bool | None:
return cls.update_forward_refs()

0 comments on commit 45d95e6

Please sign in to comment.