From d2e661f0f48bbd05c9a291bd178779745be98fb8 Mon Sep 17 00:00:00 2001 From: Kdairatchi <96064915+kdairatchi@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:29:12 -0400 Subject: [PATCH] python: allow ROARMessage init via field names and wire aliases --- .github/workflows/ci.yml | 3 ++- python/src/roar_sdk/_compat.py | 17 ++++++++--------- python/src/roar_sdk/types.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f9fac5..35f9682 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,8 @@ jobs: - name: typecheck — mypy run: mypy src/roar_sdk/ --ignore-missing-imports working-directory: python - - run: pytest tests/conformance/ -v + - name: conformance tests + run: pytest tests/test_conformance*.py -v working-directory: . - name: cross-SDK interop tests run: pytest tests/test_cross_sdk_interop.py -v diff --git a/python/src/roar_sdk/_compat.py b/python/src/roar_sdk/_compat.py index d987f74..e10a030 100644 --- a/python/src/roar_sdk/_compat.py +++ b/python/src/roar_sdk/_compat.py @@ -1,11 +1,10 @@ -# Python 3.10 compatibility shim for StrEnum (added in 3.11) -try: - from enum import StrEnum -except ImportError: - from enum import Enum +"""Compatibility helpers for Python version differences.""" - class StrEnum(str, Enum): # type: ignore[no-redef] - """Backport of Python 3.11 StrEnum for Python 3.10.""" +from enum import Enum - def __str__(self) -> str: - return self.value + +class StrEnum(str, Enum): + """Lightweight StrEnum backport for consistent typing on Python 3.10+.""" + + def __str__(self) -> str: + return self.value diff --git a/python/src/roar_sdk/types.py b/python/src/roar_sdk/types.py index c87d08a..b1bb8b3 100644 --- a/python/src/roar_sdk/types.py +++ b/python/src/roar_sdk/types.py @@ -168,8 +168,8 @@ class ROARMessage(BaseModel): roar: str = "1.0" id: str = Field(default_factory=lambda: f"msg_{uuid.uuid4().hex[:10]}") - from_identity: AgentIdentity = Field(alias="from") - to_identity: AgentIdentity = Field(alias="to") + from_identity: AgentIdentity = Field(validation_alias="from", serialization_alias="from") + to_identity: AgentIdentity = Field(validation_alias="to", serialization_alias="to") intent: MessageIntent payload: Dict[str, Any] = Field(default_factory=dict) context: Dict[str, Any] = Field(default_factory=dict)