Skip to content

Commit 8f15e28

Browse files
committed
-
1 parent dfac9cc commit 8f15e28

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

source_py3/python_toolbox/nifty_collections/bagging.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numbers
88
import collections
99
import functools
10+
import copy
1011

1112
from 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+
337343
class _MutableBagMixin(_BaseBagMixin):
338344
# blocktodo: ensure all mutable methods, like __iadd__ and everything
339345

source_py3/test_python_toolbox/test_nifty_collections/test_bagging.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)