MCPcopy Create free account
hub / github.com/RefactoringGuru/design-patterns-python / undo

Method undo

src/Memento/Conceptual/main.py:151–160  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

149 self._mementos.append(self._originator.save())
150
151 def undo(self) -> None:
152 if not len(self._mementos):
153 return
154
155 memento = self._mementos.pop()
156 print(f"Caretaker: Restoring state to: {memento.get_name()}")
157 try:
158 self._originator.restore(memento)
159 except Exception:
160 self.undo()
161
162 def show_history(self) -> None:
163 print("Caretaker: Here's the list of mementos:")

Callers 1

main.pyFile · 0.80

Calls 2

restoreMethod · 0.80
get_nameMethod · 0.45

Tested by

no test coverage detected