Repository navigation
[3.15] gh-159184: Do not compare set elements when marshalling a set (GH-159196) - #159205
Merged
Merged
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manual (claude) backport of #159196 (1967a87); the automatic one conflicted.
marshalsorted 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:
WFERR_*codes instead of raising where the error is detected. The change is applied to this branch's loop, keepingWFERR_NOMEMORYwhere main setsp->error = true.MemoryError, notTypeError, so the NEWS entry saysMemoryError.test_unorderable_set_itemsandtest_unorderable_set_items_in_codeare added. On main they replacetest_error_in_set_item, which came from marshal replaces the exception raised while writing with a generic ValueError #156942 and does not exist here.marshal.dumps()raisesTypeErrorfor a set containing several complex NaNs #159184