Skip to content

Latest commit

 

History

History
22 lines (12 loc) · 917 Bytes

File metadata and controls

22 lines (12 loc) · 917 Bytes

pyserde: Union Argument Order and Optional Cache Reuse

Upstream PR: yukinarit/pyserde#764

Bug

Union[None, X] could serialize incorrectly after Optional[X] had already been inspected. The behavior depended on argument order and cache reuse inside the compatibility helper.

Contract

Union[None, X] and Optional[X] are related, but serializers should not reuse cached classification in a way that changes behavior based on which type was seen first.

Fix

The fix removed caching from serde.compat.is_opt(), keeping each union inspection tied to the actual type expression being checked.

Verification

  • uv run pytest tests/test_union.py::test_union_none_first_argument_order -q -> 1 passed
  • uv run ruff check serde/compat.py tests/test_union.py -> passed

CI failures observed on the PR were triaged as unrelated to the changed files.