Skip to content

bpo-29535: Remove promize about hash randomization of datetime objects.#15269

Merged
serhiy-storchaka merged 1 commit into
python:masterfrom
serhiy-storchaka:datetime-hash
Aug 24, 2019
Merged

bpo-29535: Remove promize about hash randomization of datetime objects.#15269
serhiy-storchaka merged 1 commit into
python:masterfrom
serhiy-storchaka:datetime-hash

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 14, 2019

Copy link
Copy Markdown
Member

Comment thread Python/initconfig.c
"PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n"
" to seed the hashes of str, bytes and datetime objects. It can also be\n"
" set to an integer in the range [0,4294967295] to get hash values with a\n"
" to seed the hashes of str and bytes objects. It can also be set to an\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't exactly true. PYTHONHASHSEED is also used to seed the hashes of datetime objects (in the cases where hash randomization was implemented for datetime and time objects, mainly in the C implementations).

Would it be better to perhaps change the hash of datetime and time to always be non-randomized, so that the documentation is accurate?

@serhiy-storchaka serhiy-storchaka Aug 24, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not the purpose of setting PYTHONHASHSEED. Yes, the hashes of datetime objects can be affected by setting PYTHONHASHSEED, as well as hashes of any compound object which contains str or bytes objects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what do you mean?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The datetimes objects are not special. Changing their hashes is a side effect of changing the hash of bytes objects.

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-15454 is a backport of this pull request to the 3.8 branch.

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker e9c90aa43144b0be1e4e393e8cb549573437a5da 3.7

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 24, 2019
…s. (pythonGH-15269)

(cherry picked from commit e9c90aa)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka removed their assignment Aug 24, 2019
miss-islington added a commit that referenced this pull request Aug 24, 2019
…s. (GH-15269)

(cherry picked from commit e9c90aa)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants