Skip to content

[3.15] gh-159184: Do not compare set elements when marshalling a set (GH-159196) - #159205

Merged
gpshead merged 1 commit into
python:3.15from
gpshead:backport-1967a87-3.15
Oct 11, 2026
Merged

gpshead merged 1 commit into
python:3.15from
gpshead:backport-1967a87-3.15

Conversation

@gpshead

@gpshead gpshead commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Manual (claude) backport of #159196 (1967a87); the automatic one conflicted.

marshal sorted set elements as (dump, element) pairs, so elements with the same dump were compared. That fails for a set of several complex NaNs, which the compiler can produce by constant folding, making the module impossible to marshal. The fix sorts (dump, index, element) tuples, in which the indexes always differ, so elements are never compared. Output is unchanged wherever marshalling worked before.

Differences from the main commit:

…a set (pythonGH-159196)

Set elements are written in the order of their dumps.  They were sorted
as (dump, element) pairs, so elements with the same dump were compared.
That failed for a set of several complex NaNs, which the compiler can
produce by constant folding, making the module impossible to marshal.
On this branch the failure was reported as MemoryError.

Sort (dump, index, element) tuples, in which the indexes are all
different.  Elements with the same dump stay in the order of the set,
as float NaNs did before.

(cherry picked from commit 1967a87)
@bedevere-app bedevere-app Bot added the type-bug An unexpected behavior, bug, or error label Oct 11, 2026
@gpshead gpshead self-assigned this Oct 11, 2026
@gpshead
gpshead enabled auto-merge (squash) October 11, 2026 23:02
@gpshead
gpshead merged commit 8c7ac57 into python:3.15 Oct 11, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant