Skip to content

Commit

Permalink
more removals
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jan 3, 2025
1 parent a1896fc commit 1881445
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/ome_types/_mixins/_base_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _update_set_fields(self) -> None:
Because pydantic isn't aware of mutations to sequences, it can't tell when
a field has been "set" by mutating a sequence. This method updates the
self.__fields_set__ attribute to reflect that. We assume that if an attribute
`model_fields_set` attribute to reflect that. We assume that if an attribute
is not None, and is not equal to the default value, then it has been set.
"""
update_set_fields(self)
Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/_pydantic_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def update_set_fields(self: BaseModel) -> None:
Because pydantic isn't aware of mutations to sequences, it can't tell when
a field has been "set" by mutating a sequence. This method updates the
self.__fields_set__ attribute to reflect that. We assume that if an attribute
`model_fields_set` attribute to reflect that. We assume that if an attribute
is not None, and is not equal to the default value, then it has been set.
"""
for field_name, field in self.model_fields.items():
Expand Down
5 changes: 1 addition & 4 deletions src/ome_types/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def update(self, ome: OME | str | None | dict) -> None:
self._current_path = ome
else:
raise TypeError("must be OME object or string")
if hasattr(_ome, "model_dump"):
data = _ome.model_dump(exclude_unset=True)
else:
data = _ome.dict(exclude_unset=True)
data = _ome.model_dump(exclude_unset=True)

Check warning on line 142 in src/ome_types/widget.py

View check run for this annotation

Codecov / codecov/patch

src/ome_types/widget.py#L142

Added line #L142 was not covered by tests
self._fill_item(data)

def _fill_item(self, obj: Any, item: QTreeWidgetItem = None) -> None:
Expand Down
52 changes: 0 additions & 52 deletions tests/test_names.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
from __future__ import annotations

import json
from pathlib import Path
from typing import TYPE_CHECKING, Any

import pytest
from pydantic import BaseModel, version

import ome_types
from ome_types import model

if TYPE_CHECKING:
from collections.abc import Sequence

PYDANTIC2 = version.VERSION.startswith("2")
TESTS = Path(__file__).parent
KNOWN_CHANGES: dict[str, list[tuple[str, str | None]]] = {
"OME.datasets": [
Expand Down Expand Up @@ -88,51 +81,6 @@
}


def _assert_names_match(
old: dict[str, Any], new: dict[str, Any], path: Sequence[str] = ()
) -> None:
"""Make sure every key in old is in new, or that it's in KNOWN_CHANGES."""
for old_key, value in old.items():
new_key = old_key
if old_key not in new:
_path = ".".join(path)
if _path in KNOWN_CHANGES:
for from_, new_key in KNOWN_CHANGES[_path]: # type: ignore
if old_key == from_ and (new_key in new or new_key is None):
break
else:
raise AssertionError(
f"Key {old_key!r} not in new model at {_path}: {list(new)}"
)
else:
raise AssertionError(f"{_path!r} not in KNOWN_CHANGES")

if isinstance(value, dict) and new_key in new:
_assert_names_match(value, new[new_key], (*path, old_key))


def _get_fields(cls: type[BaseModel]) -> dict[str, Any]:
from pydantic.typing import display_as_type

fields = {}
for name, field in cls.__fields__.items():
if name.startswith("_"):
continue
if isinstance(field.type_, type) and issubclass(field.type_, BaseModel):
fields[name] = _get_fields(field.type_)
else:
fields[name] = display_as_type(field.outer_type_) # type: ignore
return fields


@pytest.mark.skipif(PYDANTIC2, reason="no need to check pydantic 2")
def test_names() -> None:
with (TESTS / "data" / "old_model.json").open() as f:
old_names = json.load(f)
new_names = _get_fields(ome_types.model.OME)
_assert_names_match(old_names, new_names, ("OME",))


V1_EXPORTS = [
("affine_transform", "AffineTransform"),
("annotation", "Annotation"),
Expand Down

0 comments on commit 1881445

Please sign in to comment.