MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_reduce_copying

Method test_reduce_copying

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

Source from the content-addressed store, hash-verified

5597
5598 @support.thread_unsafe
5599 def test_reduce_copying(self):
5600 # Tests pickling and copying new-style classes and objects.
5601 global C1
5602 class C1:
5603 "The state of this class is copyable via its instance dict."
5604 ARGS = (1, 2)
5605 NEED_DICT_COPYING = True
5606 def __init__(self, a, b):
5607 super().__init__()
5608 self.a = a
5609 self.b = b
5610 def __repr__(self):
5611 return "C1(%r, %r)" % (self.a, self.b)
5612
5613 global C2
5614 class C2(list):
5615 "A list subclass copyable via __getnewargs__."
5616 ARGS = (1, 2)
5617 NEED_DICT_COPYING = False
5618 def __new__(cls, a, b):
5619 self = super().__new__(cls)
5620 self.a = a
5621 self.b = b
5622 return self
5623 def __init__(self, *args):
5624 super().__init__()
5625 # This helps testing that __init__ is not called during the
5626 # unpickling process, which would cause extra appends.
5627 self.append("cheese")
5628 @classmethod
5629 def __getnewargs__(cls):
5630 return cls.ARGS
5631 def __repr__(self):
5632 return "C2(%r, %r)<%r>" % (self.a, self.b, list(self))
5633
5634 global C3
5635 class C3(list):
5636 "A list subclass copyable via __getstate__."
5637 ARGS = (1, 2)
5638 NEED_DICT_COPYING = False
5639 def __init__(self, a, b):
5640 self.a = a
5641 self.b = b
5642 # This helps testing that __init__ is not called during the
5643 # unpickling process, which would cause extra appends.
5644 self.append("cheese")
5645 @classmethod
5646 def __getstate__(cls):
5647 return cls.ARGS
5648 def __setstate__(self, state):
5649 a, b = state
5650 self.a = a
5651 self.b = b
5652 def __repr__(self):
5653 return "C3(%r, %r)<%r>" % (self.a, self.b, list(self))
5654
5655 global C4
5656 class C4(int):

Callers

nothing calls this directly

Calls 8

_assert_is_copyMethod · 0.95
deepcopyFunction · 0.90
getattrFunction · 0.85
subTestMethod · 0.80
clsClass · 0.50
copyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected