diff -r -c python-cvs/dist/src/Lib/copy.py python/dist/src/Lib/copy.py *** python-cvs/dist/src/Lib/copy.py Thu Feb 27 13:14:33 2003 --- python/dist/src/Lib/copy.py Fri Mar 21 21:14:20 2003 *************** *** 334,339 **** --- 334,340 ---- if deep: args = deepcopy(args, memo) y = callable(*args) + memo[id(x)] = y if listiter is not None: for item in listiter: if deep: diff -r -c python-cvs/dist/src/Lib/test/test_copy.py python/dist/src/Lib/test/test_copy.py *** python-cvs/dist/src/Lib/test/test_copy.py Tue Feb 18 18:19:28 2003 --- python/dist/src/Lib/test/test_copy.py Fri Mar 21 21:38:56 2003 *************** *** 174,186 **** self.assertEqual(y, x) def test_deepcopy_memo(self): x = [] ! x.append(x) y = copy.deepcopy(x) self.assertEqual(y, x) self.assert_(y is not x) self.assert_(y[0] is not x[0]) ! self.assert_(y is y[0]) def test_deepcopy_issubclass(self): # XXX Note: there's no way to test the TypeError coming out of --- 174,188 ---- self.assertEqual(y, x) def test_deepcopy_memo(self): + # Tests of reflexive objects are under type-specific sections below. + # This tests only repetitions of objects. x = [] ! x = [x, x] y = copy.deepcopy(x) self.assertEqual(y, x) self.assert_(y is not x) self.assert_(y[0] is not x[0]) ! self.assert_(y[0] is y[1]) def test_deepcopy_issubclass(self): # XXX Note: there's no way to test the TypeError coming out of *************** *** 266,271 **** --- 268,282 ---- self.assert_(x is not y) self.assert_(x[0] is not y[0]) + def test_deepcopy_reflexive_list(self): + x = [] + x.append(x) + y = copy.deepcopy(x) + self.assertEqual(y, x) + self.assert_(y is not x) + self.assert_(y[0] is not x[0]) + self.assert_(y is y[0]) + def test_deepcopy_tuple(self): x = ([1, 2], 3) y = copy.deepcopy(x) *************** *** 273,278 **** --- 284,298 ---- self.assert_(x is not y) self.assert_(x[0] is not y[0]) + def test_deepcopy_reflexive_tuple(self): + x = ([],) + x[0].append(x) + y = copy.deepcopy(x) + self.assertEqual(y, x) + self.assert_(y is not x) + self.assert_(y[0] is not x[0]) + self.assert_(y[0][0] is y) + def test_deepcopy_dict(self): x = {"foo": [1, 2], "bar": 3} y = copy.deepcopy(x) *************** *** 280,285 **** --- 300,314 ---- self.assert_(x is not y) self.assert_(x["foo"] is not y["foo"]) + def test_deepcopy_reflexive_dict(self): + x = {} + x['foo'] = x + y = copy.deepcopy(x) + self.assertEqual(y, x) + self.assert_(y is not x) + self.assert_(y['foo'] is y) + self.assertEqual(y, {'foo': y}) + def test_deepcopy_keepalive(self): memo = {} x = 42 *************** *** 369,374 **** --- 398,412 ---- self.assert_(y is not x) self.assert_(y.foo is not x.foo) + def test_deepcopy_reflexive_inst(self): + class C: + pass + x = C() + x.foo = x + y = copy.deepcopy(x) + self.assert_(y is not x) + self.assert_(y.foo is y) + # _reconstruct() def test_reconstruct_string(self): *************** *** 421,426 **** --- 459,473 ---- y = copy.deepcopy(x) self.assertEqual(y, x) self.assert_(y.foo is not x.foo) + + def test_reconstruct_reflexive(self): + class C(object): + pass + x = C() + x.foo = x + y = copy.deepcopy(x) + self.assert_(y is not x) + self.assert_(y.foo is y) # Additions for Python 2.3 and pickle protocol 2