Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pydantic v2 #642

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cyclops/report/model_card/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class BaseModelCardConfig(BaseConfig):
class BaseModelCardField(BaseModel):
"""Base class for model card fields."""

# TODO[pydantic]: The `Config` class inherits from another class, please create the `model_config` manually.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
class Config(BaseModelCardConfig):
"""Global config for model card fields.

Expand Down
13 changes: 8 additions & 5 deletions cyclops/report/model_card/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
StrictFloat,
StrictInt,
StrictStr,
root_validator,
validator,
field_validator,
model_validator,
)

from cyclops.report.model_card.base import BaseModelCardField
Expand Down Expand Up @@ -90,7 +90,8 @@ class License(
)
text_url: Optional[AnyUrl] = Field(None, description="A URL to the license text.")

@root_validator(skip_on_failure=True)
@model_validator(skip_on_failure=True)
@classmethod
def validate_spdx_identifier(
cls: "License", # noqa: N805
values: Dict[str, StrictStr],
Expand Down Expand Up @@ -154,7 +155,8 @@ class Citation(
description="The citation content in BibTeX format.",
)

@validator("content")
@field_validator("content")
@classmethod
def parse_content(
cls: "Citation", # noqa: N805
value: StrictStr,
Expand Down Expand Up @@ -414,7 +416,8 @@ class UseCase(
),
)

@validator("kind")
@field_validator("kind")
@classmethod
def kind_must_be_valid(
cls: "UseCase", # noqa: N805
value: str,
Expand Down
2 changes: 2 additions & 0 deletions cyclops/report/model_card/model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class ModelCard(BaseModel):

"""

# TODO[pydantic]: The `Config` class inherits from another class, please create the `model_config` manually.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
class Config(BaseModelCardConfig):
"""Model Card configuration."""

Expand Down
Loading
Loading