Upstream PR: yukinarit/pyserde#764
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.
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.
The fix removed caching from serde.compat.is_opt(), keeping each union inspection tied to the actual type expression being checked.
uv run pytest tests/test_union.py::test_union_none_first_argument_order -q-> 1 passeduv 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.