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)
| 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.""" |
no test coverage detected