Commits

Antonio Cuni  committed 3cc63ec Draft

implement the - operator between dict views and sets

  • Participants
  • Parent commits b66b8ad
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/objspace/std/dictmultiobject.py

 xor__DictViewItems_DictViewItems = xor__DictViewKeys_DictViewKeys
 xor__DictViewItems_settypedef = xor__DictViewKeys_DictViewKeys
 
+def sub__DictViewKeys_DictViewKeys(space, w_dictview, w_otherview):
+    w_set = space.call_function(space.w_set, w_dictview)
+    space.call_method(w_set, "difference_update", w_otherview)
+    return w_set
+sub__DictViewKeys_settypedef = sub__DictViewKeys_DictViewKeys
+sub__DictViewItems_DictViewItems = sub__DictViewKeys_DictViewKeys
+sub__DictViewItems_settypedef = sub__DictViewKeys_DictViewKeys
+
 # ____________________________________________________________
 
 from pypy.objspace.std import dicttype

File pypy/objspace/std/test/test_dictmultiobject.py

         assert d1.keys() ^ set(d2.keys()) == set('ac')
         assert d1.keys() ^ set(d3.keys()) == set('abde')
 
+        assert d1.keys() - d1.keys() == set()
+        assert d1.keys() - d2.keys() == set('a')
+        assert d1.keys() - d3.keys() == set('ab')
+        assert d1.keys() - set(d1.keys()) == set()
+        assert d1.keys() - set(d2.keys()) == set('a')
+        assert d1.keys() - set(d3.keys()) == set('ab')
+
     def test_items_set_operations(self):
         d1 = {'a': 1, 'b': 2}
         d2 = {'a': 2, 'b': 2}
         assert (d1.items() ^ d3.items() ==
                 set([('a', 1), ('b', 2), ('d', 4), ('e', 5)]))
 
+        assert d1.items() - d1.items() == set()
+        assert d1.items() - d2.items() == set([('a', 1)])
+        assert d1.items() - d3.items() == set([('a', 1), ('b', 2)])
+
 
 class AppTestStrategies(object):
     def setup_class(cls):