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

Add __hash__ for IntEnum #6849

Merged
merged 3 commits into from Mar 22, 2021
Merged

Add __hash__ for IntEnum #6849

merged 3 commits into from Mar 22, 2021

Conversation

HPLegion
Copy link
Contributor

Hi :-)

Partially solving #5911

This patch adds __hash__ capability for IntEnums. I think this would be a nice addition, because I like to use enums as keys for the typed Dict, since there is less risk of introducing typos.

I have been using this inside my own code for a while, but I had mistakenly thought that the hashes I created are different from the CPython hashes.
Today I realised that the CPython hash for an IntEnum is in fact simply int.__hash__ (value) so I think this could move into numba.

Is it frowned upon to use the extension API for internals?

Cheers!

@stuartarchibald
Copy link
Contributor

Thanks for the patch @HPLegion

Is it frowned upon to use the extension API for internals?

It's encouraged!

Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

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

Thanks for the patch, one minor thing to resolve else looks good.

numba/cpython/enumimpl.py Outdated Show resolved Hide resolved
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 2 - In Progress labels Mar 22, 2021
@stuartarchibald stuartarchibald added this to the Numba 0.54 RC milestone Mar 22, 2021
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

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

Thanks for the patch and fixes.

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge Effort - short Short size effort needed and removed 4 - Waiting on author Waiting for author to respond to review labels Mar 22, 2021
@sklam sklam merged commit b044345 into numba:master Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge Effort - short Short size effort needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants