Skip to content
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

gh-111389: expose _PyHASH_INF/BITS/MODULUS/IMAG macros as public #111418

Merged
merged 18 commits into from
Mar 9, 2024

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Oct 28, 2023

@vstinner
Copy link
Member

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

@skirpichev
Copy link
Member Author

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)?

Doc/library/sys.rst Outdated Show resolved Hide resolved
Copy link
Member

@vstinner vstinner 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

bedevere-app bot commented Oct 30, 2023

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
Member Author

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
Member Author

I have made the requested changes; please review again

@skirpichev
Copy link
Member Author

I didn't expect the Spanish Inquisition

@skirpichev
Copy link
Member Author

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

@vstinner
Copy link
Member

vstinner commented Nov 4, 2023

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

@skirpichev
Copy link
Member Author

BTW, maybe we shouldn't export _PyHASH_BITS.

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

Copy link
Member

@vstinner vstinner 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.

Include/pyhash.h Outdated Show resolved Hide resolved
@skirpichev skirpichev changed the title gh-111389: restoring _PyHASH_INF/BITS/MODULUS/IMAG macroses as public gh-111389: expose _PyHASH_INF/BITS/MODULUS/IMAG macros as public Nov 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
Member Author

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

@skirpichev
Copy link
Member Author

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

@skirpichev
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Mar 4, 2024

Thanks for making the requested changes!

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

Include/cpython/pyhash.h Outdated Show resolved Hide resolved
Doc/c-api/hash.rst Outdated Show resolved Hide resolved
Doc/c-api/hash.rst Outdated Show resolved Hide resolved
Copy link
Member

@vstinner vstinner 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?

Include/cpython/pyhash.h Show resolved Hide resolved
Copy link
Member

@mdickinson mdickinson 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.

@vstinner vstinner merged commit 1e68c4b into python:main Mar 9, 2024
34 checks passed
@vstinner
Copy link
Member

vstinner commented Mar 9, 2024

Merged, thank you @skirpichev.

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

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 free to 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