Skip to content

feat: add 'pythonic' serializer alias and tuple preservation #78

@27Bslash6

Description

@27Bslash6

Description

Two related improvements to the serializer system:

1. Add serializer='pythonic' alias for AutoSerializer

auto is vague — "auto-detect what?" pythonic communicates the value: preserves Python-native types.

# Current
@cache(serializer='auto')

# Proposed alias
@cache(serializer='pythonic')  # clearer intent

One-line change in SERIALIZER_REGISTRY:

SERIALIZER_REGISTRY = {
    "auto": AutoSerializer,
    "pythonic": AutoSerializer,  # alias — preserves Python types
    ...
}

2. Add tuple preservation to AutoSerializer

AutoSerializer already preserves sets and frozensets via type markers ({"__set__": True, ...}). Tuples need the same treatment:

# In _auto_default():
if isinstance(obj, tuple):
    return {"__tuple__": True, "value": list(obj)}

# In _auto_object_hook():
if obj.get("__tuple__") is True:
    return tuple(obj["value"])

Why

  • Sets are preserved, tuples are not — inconsistent
  • serializer='auto' (or 'pythonic') would then preserve tuples, sets, frozensets, datetime, UUID, Decimal
  • Default serializer='default' stays MessagePack for cross-SDK compatibility
  • The tradeoff is explicit: pythonic = Python-only type fidelity, default = cross-language safe

Evidence

From tests/competitive/test_head_to_head.py:

  • AutoSerializer preserves sets through cache roundtrip ✓
  • AutoSerializer does NOT preserve tuples through cache roundtrip ✗ (same MessagePack issue as default)
  • ~10 LOC fix in auto_serializer.py

References: #73

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions