Skip to content

Commit

Permalink
support Annotated types
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Jan 9, 2024
1 parent 4e0186a commit fcddfd6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dvc/api/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def _get_datasets() -> Dict[str, Dict[str, Any]]:
return repo.index.datasets


def _get_raw(name: str) -> Dict[str, Any]:
return _get_datasets()[name]


def get(cls: "Type[T]", name: str) -> "T":
datasets = _get_datasets()
return cls.model_validate(datasets[name])
from pydantic import TypeAdapter

d = _get_raw(name)
return TypeAdapter(cls).validate_python(d)

0 comments on commit fcddfd6

Please sign in to comment.