|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
Sorry, something went wrong.
|
None, like True and False, is a special object in Python, and should have either a constant hash, or one that can be set by specifying the random hash seed. |
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
|
There is some value in making it dependent on the hash secret (PYTHONHASHSEED):
The cost of doing that is an extra global variable and a single calculation done once upon setting the hash secret. I think that is a reasonable cost - I'll try writing it that way. EDIT: now that I did, having second thoughts - it's a larger change to CPython, and perhaps people who run their code only on platforms with ASLR disabled today will be surprised by the "non-determinism by default" we'll be introducing here. The hash secret was introduced to negate chosen input complexity attacks on builtin hash sets/maps, which is not relevant here, as None is a singleton. The "fuzzing" use case is secondary. I'm willing to go with either solution. Personally, I will benefit more from the PYTHONHASHSEED dependent hash, but I don't know that it's the right thing to do for general use. |
Sorry, something went wrong.
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
✅ Deploy Preview for python-cpython-preview canceled.
|
Sorry, something went wrong.
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
|
I'm waiting with the blurb update until we make a final decision whether to go with a hash-secret-dependent calculation or not. |
Sorry, something went wrong.
|
I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
Sorry, something went wrong.
There was a problem hiding this comment.
Let's do a simple constant hash for None.
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
There was a problem hiding this comment.
How 0xFCA86420 is chosen?
Is it better than random value?
Sorry, something went wrong.
|
The constant was chosen basically at whim (that particular value amused me); it's easier to implement as a constant because if we went with a random number we would have to make it contingent on the hash seed used to randomize str and byte hashes so that different runs of a program could be consistent (a virtual necessity for bug-hunting). If it was a truly random value (which it currently is if Python was compiled with ASLR), then program results can vary from one run to the next with no way to force them to be the same (since None's hash is not currently dependent on the PYTHONHASHSEED). |
Sorry, something went wrong.
|
it's easier to implement as a constant because if we went with a random number we would have to make it contingent on the hash seed used to randomize str and byte hashes so that different runs of a program could be consistent (a virtual necessity for bug-hunting). I just meant constant random number, like 0xb1f921305a6be69e. Since hashtable (dict and set) uses lower bits first, filling some lower bits can reduce hash collision against small constant ints. But this is not a big issue because None is just one singleton. |
Sorry, something went wrong.
|
I just meant constant random number, like 0xb1f921305a6be69e. Just noting that if a 64-bit literal is used, we'd presumably need to add a static check for 32-bit builds, and add a 32-bit "fallback" value for that case. |
Sorry, something went wrong.
|
Good point. Let's just use a 32-bit number instead. |
Sorry, something went wrong.
|
Actually, unless I'm missing something, that is a 32-bit number. |
Sorry, something went wrong.
|
I think that was in response to Inada-san's suggestion of 0xb1f921305a6be69e. |
Sorry, something went wrong.
|
Ah, that's what I was missing. I wish we had a reply directly to a comment ability. :-( |
Sorry, something went wrong.
|
Thank you for this, it allowed to make my project deterministic! I dropped a comment about it there: https://stackoverflow.com/questions/7681786/how-is-hashnone-calculated/75296606#75296606 |
Sorry, something went wrong.
|
Is this merged into 3.12? There's no mention in the changelog. |
Sorry, something went wrong.
|
Is this merged into 3.12? There's no mention in the changelog. The PR did update the blurb, and it appears in git log when I check out branch 3.12. What makes a given PR worthy of appearing in the changelog? |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.