Skip to content

Commit 9717fd2

Browse files
committed
make Pin hashable
1 parent bf0e1fa commit 9717fd2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

locale/circuitpython.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ msgstr ""
623623
msgid "Buffer length must be a multiple of 512"
624624
msgstr ""
625625

626-
#: ports/stm/common-hal/sdioio/SDCard.c
626+
#: ports/stm/common-hal/sdioio/SDCard.c shared-bindings/floppyio/__init__.c
627627
msgid "Buffer must be a multiple of 512 bytes"
628628
msgstr ""
629629

shared-bindings/microcontroller/Pin.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,28 @@ STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
7878
}
7979
}
8080

81+
//| def __hash__(self) -> int:
82+
//| """Returns a hash for the Pin."""
83+
//| ...
84+
//|
85+
STATIC mp_obj_t mcu_pin_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
86+
switch (op) {
87+
case MP_UNARY_OP_HASH: {
88+
return mp_obj_id(self_in);
89+
}
90+
default:
91+
return MP_OBJ_NULL; // op not supported
92+
}
93+
}
94+
8195
const mp_obj_type_t mcu_pin_type = {
8296
{ &mp_type_type },
97+
.flags = MP_TYPE_FLAG_EXTENDED,
8398
.name = MP_QSTR_Pin,
84-
.print = mcu_pin_print
99+
.print = mcu_pin_print,
100+
MP_TYPE_EXTENDED_FIELDS(
101+
.unary_op = mcu_pin_unary_op,
102+
)
85103
};
86104

87105
const mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj) {

0 commit comments

Comments
 (0)