Skip to content

Conversation

@skirpichev
Copy link
Member

@skirpichevskirpichev commented Oct 28, 2023

@skirpichevskirpichevforce-pushed the restore-pyhash-and-pylongnew branch from 1edec34 to 0ce377aCompareOctober 28, 2023 03:52
@vstinner
Copy link
Member

I would prefer to make them public if they are useful.

@skirpichev
Copy link
MemberAuthor

I would prefer to make them public if they are useful.

@vstinner, are you about documenting these macroses somewhere (I propose https://docs.python.org/3/library/sys.html#sys.hash_info, where we could mention them in descriptions for different fields) AND about renaming them too (add PyUnstable_ aliases)?

@skirpichevskirpichevforce-pushed the restore-pyhash-and-pylongnew branch from 1f9f2fc to 2c6002fCompareOctober 29, 2023 04:52
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

Please don't document private APIs.

@bedevere-app
Copy link

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.

@vstinner
Copy link
Member

If you want to document these constants, make them public.

@ngoldbaum
Copy link
Contributor

It looks like numpy uses _Py_HashDouble to hash numpy scalars. If we're going to expose these symbols again, is there any appetite for exposing the functions used by them in the unstable API? If not it looks like it should be straightforward to vendor the code assuming there aren't any hidden issues for making the hash values of numpy scalars possibly differ from python scalars in the future.

@skirpichev
Copy link
MemberAuthor

If you want to document these constants, make them public.

Ok, I've added PyUnstable prefixes. If that's ok, I'll add a news entry.

The other option is to revert to 0ce377a. I don't think we could just remove underscores, given the _PyHASH_NAN example.

I have made the requested changes; please review again

BTW, maybe we shouldn't export _PyHASH_BITS. This parameter is not available in sys.hash_info and examples for hashing in the docs show how to avoid using one. I'll try to patch gmpy2 to remove it's usage (seems to be trivial for mpq, but may be less efficient for mpfr). I think same could be done for the Sage.

It looks like numpy uses _Py_HashDouble to hash numpy scalars.

@ngoldbaum FYI: #91744 (comment)

@skirpichev
Copy link
MemberAuthor

I have made the requested changes; please review again

@skirpichev
Copy link
MemberAuthor

I didn't expect the Spanish Inquisition

@skirpichev
Copy link
MemberAuthor

@vstinner, not sure why bot isn't working, but I think I did requested changes.

@vstinner
Copy link
Member

Sorry, I was struggling with #111089 this week. I will try to go through all #111481 issues next week.

@skirpichev
Copy link
MemberAuthor

BTW, maybe we shouldn't export _PyHASH_BITS.

Hmm, no, it seems we really want this, e.g.: gmpy2/gmpy2#452 (see first removed commit). Then maybe we should expose this in sys.hash_info struct too?

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

I'm working on PR #112095 which adds an "infrastructure" to test the PyHash API. I suggest waiting until this PR is merged before considering exposing these constants to the public C API.

@skirpichevskirpichev changed the title gh-111389: restoring _PyHASH_INF/BITS/MODULUS/IMAG macroses as publicgh-111389: expose _PyHASH_INF/BITS/MODULUS/IMAG macros as publicNov 16, 2023
Was rendered: "See also the PyTypeObject.tp_hash member and Hashing of numeric types for more details about hashing of numeric types."
@skirpichev
Copy link
MemberAuthor

Perhaps, I should use Py_HASH_* naming convention? (Given #112449)

@skirpichev
Copy link
MemberAuthor

@vstinner, #112449 was closed. On another hand, Py_HashPointer() function was added. Does it make sense to keep this pr?

@skirpichev
Copy link
MemberAuthor

I have made the requested changes; please review again

@bedevere-app
Copy link

Thanks for making the requested changes!

@vstinner: please review the changes made to this pull request.

@skirpichevskirpichev requested a review from gpshead as a code ownerMarch 8, 2024 10:30
@skirpichevskirpichev requested a review from vstinnerMarch 8, 2024 10:34
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM, I just suggest to add a comment.

@mdickinson: Would you mind to double check this PR?

Copy link
Member

@mdickinsonmdickinson left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

@vstinnervstinner merged commit 1e68c4b into python:mainMar 9, 2024
@vstinner
Copy link
Member

Merged, thank you @skirpichev.

@skirpichevskirpichev deleted the restore-pyhash-and-pylongnew branch March 10, 2024 00:11
@skirpichev
Copy link
MemberAuthor

Thanks to all for review and patience.

adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@skirpichev@vstinner@ngoldbaum@mdickinson