@staticmethod
def _close_widget(widget):
    """
        Closes the given widgets and handles cases where the widget has been
        clone or is a clone of another widget
        """
    if widget is None:
        return
    try:
        widget.document().setParent(None)
        widget.syntax_highlighter.setParent(None)
    except AttributeError:
        pass
    clones = []
    if hasattr(widget, 'original') and widget.original:
        widget.original.clones.remove(widget)
        try:
            widget.setDocument(None)
        except AttributeError:
            pass
    elif hasattr(widget, 'clones'):
        clones = widget.clones
    try:
        widget.close(clear=len(clones) == 0)
    except (AttributeError, TypeError):
        widget.close()
    return clones
