py/objset: Check that RHS of a binary op is a set/frozenset.
CPython docs explicitly state that the RHS of a set/frozenset binary op
must be a set to prevent user errors. It also preserves commutativity of
the ops, eg: "abc" & set() is a TypeError, and so should be set() & "abc".
This change actually decreases unix (x64) code by 160 bytes; it increases
stm32 by 4 bytes and esp8266 by 28 bytes (but previous patch already
introduced a much large saving).
diff --git a/py/objset.c b/py/objset.c
index 6dede88..80ed263 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -463,6 +463,10 @@
#else
bool update = true;
#endif
+ if (op != MP_BINARY_OP_IN && !is_set_or_frozenset(rhs)) {
+ // For all ops except containment the RHS must be a set/frozenset
+ return MP_OBJ_NULL;
+ }
switch (op) {
case MP_BINARY_OP_OR:
return set_union(lhs, rhs);