File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
python_toolbox/nifty_collections
test_python_toolbox/test_nifty_collections Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 77import numbers
88import collections
99import functools
10+ import copy
1011
1112from python_toolbox import math_tools
1213
@@ -334,6 +335,11 @@ def __repr__(self):
334335 '[%s]' % ', ' .join ('%s' % (item ,) for item in self .items ())
335336 )
336337
338+
339+ __deepcopy__ = lambda self , memo : type (self )(
340+ copy .deepcopy (self ._dict , memo ))
341+
342+
337343class _MutableBagMixin (_BaseBagMixin ):
338344 # blocktodo: ensure all mutable methods, like __iadd__ and everything
339345
Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ def test_common(self):
6262
6363 assert self .bag_type (bag .elements ()) == bag
6464
65- assert + bag == bag
65+ with cute_testing .RaiseAssertor (TypeError ):
66+ + bag
6667 with cute_testing .RaiseAssertor (TypeError ):
6768 - bag
6869
@@ -185,15 +186,16 @@ def test_ignores_zero(self):
185186 assert {bag_2 , bag_3 } == {bag_2 } == {bag_3 }
186187
187188 def test_copy (self ):
188- my_tuple = ('meow' ,)
189- bag = self .bag_type ({my_tuple : 3 , 'a' : 4 ,})
189+ class O : pass
190+ o = O ()
191+ bag = self .bag_type ({o : 3 })
190192 bag_shallow_copy = copy .copy (bag )
191193 bag_deep_copy = copy .deepcopy (bag )
192- assert bag_shallow_copy == bag = = bag_deep_copy
194+ assert bag_shallow_copy == bag ! = bag_deep_copy
193195 assert next (iter (bag_shallow_copy )) == next (iter (bag_shallow_copy )) \
194- != next (iter (bag_shallow_copy ))
196+ != next (iter (bag_deep_copy ))
195197 assert next (iter (bag_shallow_copy )) is next (iter (bag_shallow_copy )) \
196- is not next (iter (bag_shallow_copy ))
198+ is not next (iter (bag_deep_copy ))
197199
198200
199201
You can’t perform that action at this time.
0 commit comments