gaoflow · GitHub

added a commit to gaoflow/msgspec that referenced this pull request

Jun 17, 2026

@gaoflow

@Siyet

@Siyet

@gaoflow

type_info sorted a Literal's values with a plain sorted(), which raises
TypeError on mixed-type literals such as Literal[1, None] or
Literal[True, "yes"] since Python 3 forbids ordering across types. The
encoder/decoder already support these literals, so type_info crashing on them
is a contract violation. Sort by (type name, value) so same-type ordering is
unchanged and mixed-type literals are grouped deterministically, with a
try/except fallback. Also widen the LiteralType.values annotation to allow
mixed/None members.
Adds test_bool_literal and test_mixed_literal.
msgspec.json.schema sorted a LiteralType's values with a plain sorted(),
which raises TypeError on a mixed-type Literal like Literal[1, None]. Reuse
the same type-aware sort as inspect.type_info so the two entry points agree
and neither crashes.

@gaoflow

@gaoflow

@Siyet

Merged via the queue into msgspec:main with commit ecf2282

Jul 9, 2026

26 of 27 checks passed

@Siyet Siyet mentioned this pull request

Jul 13, 2026

Merged

Read the original on github.com ↗