Skip to content

Add __hash__ for IntEnum - #6849

Merged
sklam merged 3 commits into
numba:masterfrom
HPLegion:intenum_hash
Mar 22, 2021
Merged

sklam merged 3 commits into
numba:masterfrom
HPLegion:intenum_hash

Conversation

@HPLegion

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Thanks for the patch @HPLegion

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

It's encouraged!

@stuartarchibald stuartarchibald left a comment

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.

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

Comment thread numba/cpython/enumimpl.py Outdated
@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

@stuartarchibald stuartarchibald left a comment

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.

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.

3 participants