cultcache-py: union arm keys bounded to Int32 at definition; Missing slot typed Node; nil list elements, unit-arm extra slots and UnionArm frozen-ness pinned

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-11 04:40:33 +02:00
commit ff1138ca4c
2 changed files with 41 additions and 5 deletions

View file

@ -295,8 +295,8 @@ def define_union(
raise ValueError(f"Union {name!r} requires at least one arm")
if len(by_name) != len(by_key):
raise ValueError(f"Union {name!r} has duplicate arm names")
if any(not _is_key(key) or key < 0 for key in by_key):
raise ValueError(f"Union {name!r} arm keys must be non-negative integers")
if any(not _is_key(key) or not _INT32_MIN <= key <= _INT32_MAX for key in by_key):
raise ValueError(f"Union {name!r} arm keys must be integers within Int32")
def encode(value: Any) -> Any:
if value is None:
@ -339,6 +339,10 @@ def extract_value(value: Any, extractor: str | Extractor[Any]) -> str | int | fl
return getattr(value, extractor, None)
_INT32_MIN = -(2**31)
_INT32_MAX = 2**31 - 1
def _is_key(value: Any) -> bool:
return isinstance(value, int) and not isinstance(value, bool)