chore: better name checks for ProgramElement

This commit is contained in:
2026-01-30 19:30:40 +01:00
parent 1337b1f06b
commit b53bf872a5

View File

@@ -7,7 +7,7 @@ University within the Software Project course.
from enum import Enum
from typing import Literal
from pydantic import UUID4, BaseModel
from pydantic import UUID4, BaseModel, field_validator
class ProgramElement(BaseModel):
@@ -24,6 +24,13 @@ class ProgramElement(BaseModel):
# To make program elements hashable
model_config = {"frozen": True}
@field_validator("name")
@classmethod
def name_must_not_start_with_number(cls, v: str) -> str:
if v and v[0].isdigit():
raise ValueError('Field "name" must not start with a number.')
return v
class LogicalOperator(Enum):
"""
@@ -105,6 +112,7 @@ class InferredBelief(ProgramElement):
left: Belief
right: Belief
class EmotionBelief(ProgramElement):
"""
Represents a belief that is set when a certain emotion is detected.
@@ -115,6 +123,7 @@ class EmotionBelief(ProgramElement):
name: str = ""
emotion: str
class Norm(ProgramElement):
"""
Base class for behavioral norms that guide the robot's interactions.
@@ -329,4 +338,4 @@ class Program(BaseModel):
if __name__ == "__main__":
input = input("Enter program JSON: ")
program = Program.model_validate_json(input)
print(program)
print(program)