Skip to content

bpo-29535: make datetime hashes non-deterministic #15264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from

Conversation

epicfaace
Copy link
Contributor

@epicfaace epicfaace commented Aug 14, 2019

This PR does the following:

  • Make the hash of datetime.datetime (with a timezone) non-deterministic in the Python datetime lib.
  • Make the hash of datetime.datetime (with a timezone) non-deterministic in the C datetime lib.
  • Make the hash of datetime.datetime (with a timezone) non-deterministic in the C datetime lib.
  • Make the hash of datetime.time (with a timezone such that either 1) time - timezone < 0 [underflow] or 2) time - timezone > max_time [overflow] non-deterministic in the Python datetime lib.
  • Make sure datetime tests in test_hash.py cover both the C datetime lib and the Python datetime lib (previously they covered only the C datetime lib), and cover the cases above.

https://bugs.python.org/issue29535

if h < 0:
h = -1 * h
if h >= 24:
h = h - 24
Copy link
Member

Choose a reason for hiding this comment

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

These four lines seem a tad heavy (and odd). Would a simple h %= 24 work here?

@epicfaace
Copy link
Contributor Author

epicfaace commented Aug 23, 2019

Closing this as per discussion in bpo-29535.

@epicfaace epicfaace closed this Aug 23, 2019
@epicfaace epicfaace deleted the datetime branch August 23, 2019 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants