Private
Public Access
0
0

feat(types): add JsonPrimitive + JsonValue TypeAliases (t0_3)

Phase 0 of any_type_componentization_20260621. Extends src/type_aliases.py
with two recursive-friendly TypeAliases for JSON wire format (used by
Phase 5 api_hooks WebSocketMessage):

- JsonPrimitive: str | int | float | bool | None
- JsonValue: JsonPrimitive | list['JsonValue'] | dict[str, 'JsonValue']

The forward-ref 'JsonValue' strings work because from __future__ import
annotations is at the top of the module (PEP 563 + PEP 613 TypeAlias).

Tests added (4 new, 14 total):
- test_json_primitive_alias_resolves_to_union: hints exposes JsonPrimitive
- test_json_value_alias_resolves_to_recursive_union: hints exposes JsonValue
- test_json_value_accepts_primitive_dict: dict[str, JsonValue] runtime use
- test_json_value_accepts_nested_structures: nested dict+list round-trip

Verification:
  uv run pytest tests/test_type_aliases.py --timeout=30
    14 passed in 2.97s
This commit is contained in:
2026-06-21 15:57:40 -04:00
parent 335f9080f5
commit be4ec0a459
2 changed files with 36 additions and 1 deletions
+3
View File
@@ -18,6 +18,9 @@ ToolCall: TypeAlias = Metadata
CommsLogCallback: TypeAlias = Callable[[CommsLogEntry], None]
JsonPrimitive: TypeAlias = str | int | float | bool | None
JsonValue: TypeAlias = JsonPrimitive | list["JsonValue"] | dict[str, "JsonValue"]
class FileItemsDiff(NamedTuple):
refreshed: FileItems