Skip to main content

collections-undo

General undo/redo implementation in Python. → Documentation

Installation

pip install -U collections-undo

Basic usage

You'll have to create reversible functions using UndoManager.

from collections_undo import UndoManager

class A:
    mgr = UndoManager()

    @mgr.undoable  # create a reversible function
    def f(self, x):
        print("do", x)

    @f.undo_def  # define undo
    def f(self, x):
        print("undo", x)

a = A()

a.f(0)  # Out: "do" 0
a.mgr.undo()  # Out: "undo" 0
a.mgr.redo()  # Out: "do" 0

ABC-like undo implementation

To avoid careless errors, ABC-like interface will be useful.

from collections_undo.abc import UndoableABC, undoablemethod, undo_def

class A(UndoableABC):
    @undoablemethod
    def f(self, x):
        print("do", x)

    @undo_def(f)
    def f(self, x):
        print("undo", x)

a = A()  # OK

a.f(0)  # Out: "do" 0
a.undo()  # Out: "undo" 0
a.redo()  # Out: "do" 0

If undo is not defined, construction fails.

class A(UndoableABC):
    @undoablemethod
    def f(self, x):
        ...

a = A()  # TypeError

class B(A):
    @undo_def(A.f)
    def f(self, x):
        ...

b = B()  # OK

Builtin undoable objects

These mutable classes have undo and redo method to handle operations that mutate the object.

  • Ready-to-use classes

    • UndoableList ... insert, __setitem__, extend etc. are undoable.
    • UndoableDict ... __setitem__, update etc. are undoable.
    • UndoableSet ... add, discard etc. are undoable.
  • Abstract classes

    • AbstractUndoableList
    • AbstractUndoableDict
    • AbstractUndoableSet

Metadata

Release files for collections-undo 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collections-undo 0.0.7
File Size Uploaded
collections-undo-0.0.7.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for collections-undo 0.0.7
File Interpreter ABI Platform
collections_undo-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 43.2 kB

Release files / collections-undo-0.0.7.tar.gz

Download URL collections-undo-0.0.7.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b161f628510f64fbe2889c35b397553320e6efe7dd106408d3b069affede3ac4
BLAKE2b-256 checksum
How to use checksums
7e1c12b3599e8ec6f901f0c8a1baeeec2910c039c188e120e675f3121a4a8ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.0 importlib_metadata/4.13.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.7

Release files / collections_undo-0.0.7-py3-none-any.whl

Download URL collections_undo-0.0.7-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac1dda443a9efac96725832db1393d203ff0d8a47efabd306b1eb5002be54f04
BLAKE2b-256 checksum
How to use checksums
1475a4c3800ea402a27c870a0fd4bef41d627d3176fe97c21f870a4759744d58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.0 importlib_metadata/4.13.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page