summaryrefslogtreecommitdiff
path: root/tests/basics/set_binop.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-10-03 17:56:27 +1100
committerDamien George <damien.p.george@gmail.com>2017-10-03 17:56:27 +1100
commit2ac1364688cd3ee313661e82a336663551986fc8 (patch)
tree4e69bc7e8d09cb3e4456275e7eba8fcffcd4de0c /tests/basics/set_binop.py
parent01978648fdc317c13b17ba186c82df4fb8a5cbac (diff)
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).
Diffstat (limited to 'tests/basics/set_binop.py')
-rw-r--r--tests/basics/set_binop.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/basics/set_binop.py b/tests/basics/set_binop.py
index 7848920b6..bc76533b1 100644
--- a/tests/basics/set_binop.py
+++ b/tests/basics/set_binop.py
@@ -47,6 +47,18 @@ s1 = s2 = set('abc')
s1 -= set('ad')
print(s1 is s2, len(s1))
+# RHS must be a set
+try:
+ print(set('12') >= '1')
+except TypeError:
+ print('TypeError')
+
+# RHS must be a set
+try:
+ print(set('12') <= '123')
+except TypeError:
+ print('TypeError')
+
# unsupported operator
try:
set('abc') * 2