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

make Pin hashable #6342

Merged
merged 2 commits into from
May 4, 2022
Merged

make Pin hashable #6342

merged 2 commits into from
May 4, 2022

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented May 3, 2022

Fixes #6179.

I keep encountering cases where I would like to microcontroller.Pin objects to be in a set() or be dictionary keys.

@jepler
Copy link
Member

jepler commented May 3, 2022

Can you use this existing function?

mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
    switch (op) {
        case MP_UNARY_OP_HASH:
            return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in);
        default:
            return MP_OBJ_NULL;      // op not supported
    }    
}

It's used, for instance, for function objects unary op slot so that they can be set members...

@dhalbert
Copy link
Collaborator Author

dhalbert commented May 3, 2022

Can you use this existing function?

Oh, sure, I didn't realize it existed. I have some other places I can use it too.

jepler
jepler previously approved these changes May 3, 2022
Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good, didn't test. Too bad none of the other savings are in things enabled in our tiniest ports.

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

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

I don't see what changed since the previous iteration, still looks OK as long as it's green.

@dhalbert
Copy link
Collaborator Author

dhalbert commented May 4, 2022

There was a stray < character at the end of one file, I think from typing in the wrong window. Thanks!

@dhalbert dhalbert merged commit ce959a9 into adafruit:main May 4, 2022
@dhalbert dhalbert deleted the pin-hash branch May 4, 2022 02:43
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.

Make microcontroller.Pin hashable, so pins can be used as dictionary keys
2 participants