-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use computed_field in Module model class
- Loading branch information
Showing
1 changed file
with
6 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
from typing import Any, Optional | ||
from typing import Any | ||
|
||
from nerdd_module.config import Module as NerddModule | ||
from pydantic import model_validator | ||
from pydantic import computed_field, model_validator | ||
|
||
__all__ = ["Module"] | ||
|
||
|
||
class Module(NerddModule): | ||
id: Optional[str] = None | ||
|
||
@model_validator(mode="after") | ||
@classmethod | ||
def validate_model(cls, values: Any) -> Any: | ||
assert isinstance(values, Module) | ||
|
||
module = super().validate_model(values) | ||
|
||
@computed_field | ||
@property | ||
def id(self) -> str: | ||
# TODO: incorporate versioning | ||
# compute the primary key from name and version | ||
# if "version" in module.keys(): | ||
# version = module["version"] | ||
# else: | ||
# version = "1.0.0" | ||
# name = module["name"] | ||
module.id = module.name | ||
|
||
return module | ||
return self.name |