GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — gh-159184: Do not compare set elements when marshalling a set by gpshead · Pull Request #159196 · python/cpython Conversation
Member
>>> marshal.dumps(frozenset({complex('nan'), complex('nan')})) TypeError: '<' not supported between instances of 'complex' and 'complex' >>> code = compile("x in {(1e999-1e999)*1j, (1e999-1e999)*2j}", "m.py", "exec") >>> marshal.dumps(code) # so no .pyc can be written for this module TypeError: '<' not supported between instances of 'complex' and 'complex' Changeflowchart TB
subgraph before["main"]
direction TB
b1["list of (dump, element)"] --> b2["PyList_Sort()"]
b2 --> b3{"equal dumps?"}
b3 -- no --> b4["ordered by dump"]
b3 -- yes --> b5["compares the elements"]
b5 -- complex --> b6["TypeError"]
b5 -- "float NaN" --> b7["neither is smaller:<br>left in set order"]
end
subgraph after["this PR"]
direction TB
a1["list of (dump, index, element)<br>index = position in the set"] --> a2["PyList_Sort()"]
a2 --> a3{"equal dumps?"}
a3 -- no --> a4["ordered by dump"]
a3 -- yes --> a5["compares the indexes,<br>which always differ:<br>left in set order"]
end
The output is unchanged wherever marshalling worked before: elements with different dumps are ordered by dump, and float NaNs with equal dumps stay in set order as they did. The only difference is that elements are never compared. This is the small part of gh-159184 that can be backported. The other part, that the order of elements with equal dumps follows their addresses, needs #159192 and is a separate PR. This touches the same block as the PR for gh-159185; whichever is merged second needs a one-line conflict resolved. Tests
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsSet 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 raised TypeError for a set of several complex NaNs, which the compiler can produce by constant folding, making the module impossible to marshal. 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.
gpshead
force-pushed
the
marshal-set-sort-bytes
branch
from
9ae5920 to
910690f
Compare
Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
gpshead
added a commit
that referenced
this pull request
…H-159196) (#159206) 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)
gpshead
added a commit
that referenced
this pull request
…H-159196) (#159205) 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)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesLabels
type-bug
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. | |||||
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |