Skip to content

Commit

Permalink
feat: add alias to Parameter model
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 committed Aug 28, 2024
1 parent 223161b commit 3ed98b1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python/ngen_cal/src/ngen/cal/parameter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from pydantic import BaseModel, Field
from typing import Sequence
from pydantic import BaseModel, Field, root_validator
from typing import Sequence, Mapping, Optional

class Parameter(BaseModel, allow_population_by_field_name = True):
"""
Expand All @@ -11,5 +11,13 @@ class Parameter(BaseModel, allow_population_by_field_name = True):
min: float
max: float
init: float
alias: Optional[str]

@root_validator
def _set_alias(cls, values: dict) -> dict:
alias = values.get('alias', None)
if alias is None:
values['alias'] = values['name']
return values

Parameters = Sequence[Parameter]

0 comments on commit 3ed98b1

Please sign in to comment.