mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
Merge branch 'feature/909-define-basic-trait-type-using-dataclasses' into feature/911-new-traits-based-integrator
This commit is contained in:
commit
37814bc972
2 changed files with 15 additions and 6 deletions
|
|
@ -391,7 +391,7 @@ class Representation(Generic[T]): # noqa: PLR0904
|
|||
|
||||
"""
|
||||
return {
|
||||
trait_id: trait.model_dump()
|
||||
trait_id: trait.as_dict()
|
||||
for trait_id, trait in self._data.items()
|
||||
if trait and trait_id
|
||||
}
|
||||
|
|
@ -593,10 +593,6 @@ class Representation(Generic[T]): # noqa: PLR0904
|
|||
)
|
||||
raise IncompatibleTraitVersionError(msg) from e
|
||||
|
||||
if requested_version is None:
|
||||
trait_class = e.found_trait
|
||||
requested_version = found_version
|
||||
|
||||
if found_version is None:
|
||||
msg = (
|
||||
f"Trait {e.found_trait.id} found with no version, "
|
||||
|
|
@ -604,6 +600,10 @@ class Representation(Generic[T]): # noqa: PLR0904
|
|||
)
|
||||
raise IncompatibleTraitVersionError(msg) from e
|
||||
|
||||
if requested_version is None:
|
||||
trait_class = e.found_trait
|
||||
requested_version = found_version
|
||||
|
||||
if requested_version > found_version:
|
||||
error_msg = (
|
||||
f"Requested trait version {requested_version} is "
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import TYPE_CHECKING, Generic, Optional, TypeVar
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -79,6 +79,15 @@ class TraitBase(ABC):
|
|||
"""
|
||||
return re.sub(r"\.v\d+$", "", str(cls.id))
|
||||
|
||||
def as_dict(self) -> dict:
|
||||
"""Return trait as dictionary.
|
||||
|
||||
Returns:
|
||||
dict: Trait as dictionary.
|
||||
|
||||
"""
|
||||
return asdict(self)
|
||||
|
||||
|
||||
class IncompatibleTraitVersionError(Exception):
|
||||
"""Incompatible trait version exception.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue