Skip to content

Commit

Permalink
Prepare for higlass-schema pydantic migration
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Nov 10, 2024
1 parent 0f95bdf commit ebe660d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/higlass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
)

import higlass_schema as hgs
from pydantic import BaseModel
from pydantic import RootModel

import higlass._display as display
import higlass._utils as utils

__all__ = [
"CombinedTrack",
"EnumTrack",
"HeatmapTrack",
"IndependentViewportProjectionTrack",
"CombinedTrack",
"PluginTrack",
"TrackT",
"View",
"ViewT",
"Viewconf",
"combine",
"concat",
"divide",
"hconcat",
"vconcat",
"lock",
"track",
"vconcat",
"view",
"combine",
"divide",
"lock",
]

if TYPE_CHECKING:
Expand Down Expand Up @@ -634,18 +634,18 @@ def mapper(view):
# TODO: register plugins globally to work here?


class _TrackCreator(BaseModel):
class _TrackCreator(RootModel):
"""Create track instances from their track type.
Used internally by `hg.track` to leverage pydantic's ability to get
the appropriate base model by the track type.
Example:
-------
>>> assert isinstance(_TrackCreator(type="heatmap").__root__, HeatmapTrack)
>>> assert isinstance(_TrackCreator(type="heatmap").root, HeatmapTrack)
"""

__root__: Track
root: Track


@overload
Expand Down Expand Up @@ -688,7 +688,7 @@ def track(
if uid is None:
uid = utils.uid()
data = dict(type=type_, uid=uid, **kwargs)
return _TrackCreator.parse_obj(data).__root__
return _TrackCreator.model_validate(data).root


def view(
Expand Down

0 comments on commit ebe660d

Please sign in to comment.