_copy_atomic_types = frozenset({types.NoneType, int, float, bool, complex, str, tuple,
- bytes, frozenset, type, range, slice, property,
+ bytes, frozendict, frozenset, type, range, slice, property,
types.BuiltinFunctionType, types.EllipsisType,
types.NotImplementedType, types.FunctionType, types.CodeType,
weakref.ref, super})
return y
d[dict] = _deepcopy_dict
+def _deepcopy_frozendict(x, memo, deepcopy=deepcopy):
+ y = _deepcopy_dict(x, memo, deepcopy)
+ return frozendict(y)
+d[frozendict] = _deepcopy_frozendict
+
def _deepcopy_method(x, memo): # Copy instance methods
return type(x)(x.__func__, deepcopy(x.__self__, memo))
d[types.MethodType] = _deepcopy_method
self.assertEqual(y, x)
self.assertIsNot(y, x)
+ def test_copy_frozendict(self):
+ x = frozendict(x=1, y=2)
+ self.assertIs(copy.copy(x), x)
+ x = frozendict()
+ self.assertIs(copy.copy(x), x)
+
def test_copy_set(self):
x = {1, 2, 3}
y = copy.copy(x)
self.assertIsNot(x, y)
self.assertIsNot(x["foo"], y["foo"])
+ def test_deepcopy_frozendict(self):
+ x = frozendict({"foo": [1, 2], "bar": 3})
+ y = copy.deepcopy(x)
+ self.assertEqual(y, x)
+ self.assertIsNot(x, y)
+ self.assertIsNot(x["foo"], y["foo"])
+
@support.skip_emscripten_stack_overflow()
@support.skip_wasi_stack_overflow()
def test_deepcopy_reflexive_dict(self):