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

refactor: use "left_to_right" in place of smart union for pydantic 2 compatibility #1132

Merged
merged 4 commits into from
Jul 8, 2024
Merged
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: 1 addition & 1 deletion .github/workflows/base_test_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ on:

jobs:
test:
name: ${{ inputs.os }} py ${{ inputs.python_version }} ${{ inputs.napari }} ${{ inputs.qt_backend }}
name: ${{ inputs.os }} py ${{ inputs.python_version }} ${{ inputs.napari }} ${{ inputs.qt_backend }} ${{ inputs.pydantic }}
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
os: ${{ matrix.os }}
qt_backend: ${{ matrix.qt_backend }}
tox_args: ${{ matrix.tox_args }}
pydantic: ${{ matrix.pydantic }}

base-test-main:
name: Base py${{ matrix.python_version }}
Expand All @@ -102,6 +103,10 @@ jobs:
- python_version: "3.9"
os: "ubuntu-22.04"
qt_backend: "PyQt6"
- python_version: "3.10"
os: "ubuntu-22.04"
qt_backend: "PyQt5"
pydantic: "_pydantic_1"
exclude:
- python_version: "3.11"
qt_backend: "PySide2"
Expand All @@ -112,6 +117,7 @@ jobs:
python_version: ${{ matrix.python_version }}
os: ${{ matrix.os }}
qt_backend: ${{ matrix.qt_backend }}
pydantic: ${{ matrix.pydantic }}

test_coverage:
needs: download_data
Expand Down
11 changes: 7 additions & 4 deletions package/PartSegCore/algorithm_describe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from importlib.metadata import version

from local_migrator import REGISTER, class_to_str
from packaging.version import parse as parse_version
from pydantic import BaseModel as PydanticBaseModel
from pydantic import create_model, validator
from pydantic.fields import FieldInfo
from pydantic.fields import Field, FieldInfo
from typing_extensions import Annotated

from PartSegCore.utils import BaseModel
Expand Down Expand Up @@ -400,13 +401,15 @@ class AlgorithmSelection(BaseModel, metaclass=AddRegisterMeta): # pylint: disab
"""

name: str
values: typing.Union[typing.Dict[str, typing.Any], PydanticBaseModel]
values: typing.Union[typing.Dict[str, typing.Any], PydanticBaseModel] = Field(..., union_mode="left_to_right")
class_path: str = ""
if typing.TYPE_CHECKING:
__register__: Register

class Config:
smart_union = True
if parse_version(version("pydantic")) < parse_version("2"):

class Config:
smart_union = True

@validator("name")
def check_name(cls, v):
Expand Down
Loading