def undo(self):
        """
        Raises IndexError if more than one group is open, otherwise closes it
        and invokes undo_nested_group.
        """
        if self.grouping_level() == 1:
            self.end_grouping()
        if self._open:
            raise IndexError
        self.undo_nested_group()
        self.notify()