MCPcopy Index your code
hub / github.com/python/cpython / test_reduce_copying

Method test_reduce_copying

Lib/test/test_descr.py:5836–5958  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5834
5835 @support.thread_unsafe
5836 def test_reduce_copying(self):
5837 # Tests pickling and copying new-style classes and objects.
5838 global C1
5839 class C1:
5840 "The state of this class is copyable via its instance dict."
5841 ARGS = (1, 2)
5842 NEED_DICT_COPYING = True
5843 def __init__(self, a, b):
5844 super().__init__()
5845 self.a = a
5846 self.b = b
5847 def __repr__(self):
5848 return "C1(%r, %r)" % (self.a, self.b)
5849
5850 global C2
5851 class C2(list):
5852 "A list subclass copyable via __getnewargs__."
5853 ARGS = (1, 2)
5854 NEED_DICT_COPYING = False
5855 def __new__(cls, a, b):
5856 self = super().__new__(cls)
5857 self.a = a
5858 self.b = b
5859 return self
5860 def __init__(self, *args):
5861 super().__init__()
5862 # This helps testing that __init__ is not called during the
5863 # unpickling process, which would cause extra appends.
5864 self.append("cheese")
5865 @classmethod
5866 def __getnewargs__(cls):
5867 return cls.ARGS
5868 def __repr__(self):
5869 return "C2(%r, %r)<%r>" % (self.a, self.b, list(self))
5870
5871 global C3
5872 class C3(list):
5873 "A list subclass copyable via __getstate__."
5874 ARGS = (1, 2)
5875 NEED_DICT_COPYING = False
5876 def __init__(self, a, b):
5877 self.a = a
5878 self.b = b
5879 # This helps testing that __init__ is not called during the
5880 # unpickling process, which would cause extra appends.
5881 self.append("cheese")
5882 @classmethod
5883 def __getstate__(cls):
5884 return cls.ARGS
5885 def __setstate__(self, state):
5886 a, b = state
5887 self.a = a
5888 self.b = b
5889 def __repr__(self):
5890 return "C3(%r, %r)<%r>" % (self.a, self.b, list(self))
5891
5892 global C4
5893 class C4(int):

Callers

nothing calls this directly

Calls 7

_assert_is_copyMethod · 0.95
deepcopyFunction · 0.90
clsClass · 0.50
subTestMethod · 0.45
copyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected