0

Provide a context manager for View.{begin,end}_edit

Patryk Zawadzki 6 years ago 0

Something along the lines of:

class Editor(object):    def __init__(self, view, command, args):        self.view = view        self.command = command        self.args = args    def __enter__(self):        self.edit = self.view.begin_edit(self.command, self.args)        return self.edit    def __exit__(self, exc_type, exc_val, exc_tb):        self.view.end_edit(self.edit)
class View(…):    def edit(self, command, args):        return Editor(self, command, args)

Would allow one to forget about the problems of pairing begins with ends:

with view.edit(…, …):    do_something()    do_something_else()