py: Allow types to be hashable.
Quite natural to have d[int] = handle_int .
This commit is contained in:
parent
c6813d92db
commit
91cbe6033a
2
py/obj.c
2
py/obj.c
|
@ -118,6 +118,8 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
|
||||||
return (machine_int_t)o_in;
|
return (machine_int_t)o_in;
|
||||||
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) {
|
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) {
|
||||||
return mp_obj_tuple_hash(o_in);
|
return mp_obj_tuple_hash(o_in);
|
||||||
|
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_type)) {
|
||||||
|
return (machine_int_t)o_in;
|
||||||
|
|
||||||
// TODO hash class and instances
|
// TODO hash class and instances
|
||||||
// TODO delegate to __hash__ method if it exists
|
// TODO delegate to __hash__ method if it exists
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Types are hashable
|
||||||
|
print(hash(type) != 0)
|
||||||
|
print(hash(int) != 0)
|
||||||
|
print(hash(list) != 0)
|
||||||
|
class Foo: pass
|
||||||
|
print(hash(Foo) != 0)
|
Loading…
Reference in New Issue