Spaces:
Sleeping
Sleeping
Sai Kumar Taraka commited on
Commit ·
b8aa00f
1
Parent(s): bb9bd03
Accept width as alias for bits in FieldDef
Browse files- src/config.py +10 -1
src/config.py
CHANGED
|
@@ -6,7 +6,7 @@ import os
|
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import Dict, List, Optional, Any
|
| 8 |
|
| 9 |
-
from pydantic import BaseModel, Field
|
| 10 |
import yaml
|
| 11 |
|
| 12 |
|
|
@@ -26,6 +26,15 @@ class FieldDef(BaseModel):
|
|
| 26 |
bits: str
|
| 27 |
description: Optional[str] = None
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
class RegisterDef(BaseModel):
|
| 30 |
name: str
|
| 31 |
address: str
|
|
|
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import Dict, List, Optional, Any
|
| 8 |
|
| 9 |
+
from pydantic import BaseModel, Field, model_validator
|
| 10 |
import yaml
|
| 11 |
|
| 12 |
|
|
|
|
| 26 |
bits: str
|
| 27 |
description: Optional[str] = None
|
| 28 |
|
| 29 |
+
@model_validator(mode="before")
|
| 30 |
+
@classmethod
|
| 31 |
+
def alias_width(cls, data):
|
| 32 |
+
if isinstance(data, dict):
|
| 33 |
+
if "width" in data and "bits" not in data:
|
| 34 |
+
w = data.pop("width")
|
| 35 |
+
data["bits"] = str(w) if isinstance(w, int) else w
|
| 36 |
+
return data
|
| 37 |
+
|
| 38 |
class RegisterDef(BaseModel):
|
| 39 |
name: str
|
| 40 |
address: str
|