MCPcopy Create free account
hub / github.com/rthalley/dnspython / _clone

Method _clone

dns/set.py:73–93  ·  view source on GitHub ↗

Make a (shallow) copy of the set. There is a 'clone protocol' that subclasses of this class should use. To make a copy, first call your super's _clone() method, and use the object returned as the new instance. Then make shallow copies of the attributes defined in t

(self)

Source from the content-addressed store, hash-verified

71 return k
72
73 def _clone(self) -> "Set":
74 """Make a (shallow) copy of the set.
75
76 There is a 'clone protocol' that subclasses of this class
77 should use. To make a copy, first call your super's _clone()
78 method, and use the object returned as the new instance. Then
79 make shallow copies of the attributes defined in the subclass.
80
81 This protocol allows us to write the set algorithms that
82 return new instances (e.g. union) once, and keep using them in
83 subclasses.
84 """
85
86 if hasattr(self, "_clone_class"):
87 cls = self._clone_class # type: ignore
88 else:
89 cls = self.__class__
90 obj = cls.__new__(cls)
91 obj.items = dict()
92 obj.items.update(self.items)
93 return obj
94
95 def __copy__(self):
96 """Make a (shallow) copy of the set."""

Callers 6

__copy__Method · 0.95
copyMethod · 0.95
unionMethod · 0.95
intersectionMethod · 0.95
differenceMethod · 0.95
symmetric_differenceMethod · 0.95

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected