aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky2014-04-05 13:09:33 +0300
committerPaul Sokolovsky2014-04-05 13:10:56 +0300
commit438d504e27790bd3186051367f7c2afc266ba1e6 (patch)
tree5d4eee4acecc67d1ffb3139b9631f90333dce1ba
parent91cbe6033a8fec6b11c414670f7ed75e9598857c (diff)
objtype: Add equality test for type types.
-rw-r--r--py/objtype.c11
-rw-r--r--tests/basics/types2.py (renamed from tests/basics/types_hash.py)6
2 files changed, 17 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c
index f4ce6a4f8..6426ec2d0 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -367,6 +367,16 @@ STATIC bool type_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
return false;
}
+STATIC mp_obj_t type_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+ switch (op) {
+ case MP_BINARY_OP_EQUAL:
+ // Types can be equal only if it's the same type structure,
+ // we don't even need to check for 2nd arg type.
+ return MP_BOOL(lhs_in == rhs_in);
+ }
+ return NULL;
+}
+
const mp_obj_type_t mp_type_type = {
{ &mp_type_type },
.name = MP_QSTR_type,
@@ -375,6 +385,7 @@ const mp_obj_type_t mp_type_type = {
.call = type_call,
.load_attr = type_load_attr,
.store_attr = type_store_attr,
+ .binary_op = type_binary_op,
};
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) {
diff --git a/tests/basics/types_hash.py b/tests/basics/types2.py
index 2595097d2..83a69c918 100644
--- a/tests/basics/types_hash.py
+++ b/tests/basics/types2.py
@@ -4,3 +4,9 @@ print(hash(int) != 0)
print(hash(list) != 0)
class Foo: pass
print(hash(Foo) != 0)
+
+print(int == int)
+print(int != list)
+
+d = {}
+d[int] = float