gurudesh/pytracebugs huggingface dataset:
# Buggy code
def find_user_dict(self):
    """Return the full path to the local dictionary."""
    c = self.c
    table = (
        c.config.getString("enchant-local-dictionary"),
        # Settings first.
        g.os_path_finalize_join(g.app.homeDir, ".leo", "spellpyx.txt"),
        # #108: then the .leo directory.
        g.os_path_finalize_join(g.app.loadDir, "..", "plugins", "spellpyx.txt"),
        # The plugins directory as a last resort.
    )
    for path in table:
        if g.os_path_exists(path):
            return path
    #
    g.es_print("Do spellpyx.txt file found")
    return None


# Traceback (TypeError)
Leo Log Window
Leo 6.1-final, master branch, build b80e074204
2019-11-08 12:36:03 -0600
Python 3.8.0, PyQt version 5.13.0
Windows 10 AMD64 (build 10.0.17763) SP0
created directory: C:/Users/C050536/.leo
leoID='metaperl'
.leoID.txt created in C:/Users/C050536/.leo
current dir: C:/bin/leo-editor
load dir: C:/bin/leo-editor/leo/core
global config dir: C:/bin/leo-editor/leo/config
home dir: C:/Users/C050536
reading settings in C:/bin/leo-editor/leo/config/leoSettings.leo
Do spellpyx.txt file found
unexpected error creating: None
Traceback (most recent call last):

File "C:\bin\leo-editor\leo\commands\spellCommands.py", line 56, in create
f = open(fn, mode='wb')

TypeError: expected str, bytes or os.PathLike object, not NoneType

reading settings in C:/bin/leo-editor/leo/doc/CheatSheet.leo

# Fixed code
def find_user_dict(self):
    """Return the full path to the local dictionary."""
    c = self.c
    join = g.os_path_finalize_join
    table = (
        c.config.getString("enchant-local-dictionary"),
        # Settings first.
        join(g.app.homeDir, ".leo", "spellpyx.txt"),
        # #108: then the .leo directory.
        join(g.app.loadDir, "..", "plugins", "spellpyx.txt"),
        # The plugins directory as a last resort.
    )
    for path in table:
        if g.os_path_exists(path):
            return path
    g.es_print("Creating ~/.leo/spellpyx.txt")
    # #1453: Return the default path.
    return join(g.app.homeDir, ".leo", "spellpyx.txt")
# Buggy code
def write(self, root, sentinels=True):
    """Write a 4.x derived file.
    root is the position of an @<file> node.
    sentinels will be False for @clean and @nosent nodes.
    """
    at, c = self, self.c
    try:
        c.endEditing()
        fileName = at.initWriteIvars(
            root, root.anyAtFileNodeName(), sentinels=sentinels
        )
        # #1450.
        if not fileName or not at.precheck(fileName, root):
            at.addToOrphanList(root)
            return
        at.openOutputStream()
        at.putFile(root, sentinels=sentinels)
        at.warnAboutOrphandAndIgnoredNodes()
        contents = at.closeOutputStream()
        if at.errors:
            g.es("not written:", g.shortFileName(fileName))
            at.addToOrphanList(root)
        else:
            at.replaceFile(contents, at.encoding, fileName, root)
    except Exception:
        if hasattr(self.root.v, "tnodeList"):
            delattr(self.root.v, "tnodeList")
        at.writeException(fileName, root)


# Traceback (AttributeError)
Traceback (most recent call last):

File ".../leo/core/leoGlobals.py", line 293, in new_cmd_wrapper
func(self, event=event)

File ".../leo/core/leoFileCommands.py", line 1827, in writeMissingAtFileNodes
c.atFileCommands.writeMissing(c.p)

File ".../leo/core/leoAtFile.py", line 1327, in writeMissing
at.default_directory = c.expand_path_expression(at.default_directory) # #1341.
AttributeError: 'AtFile' object has no attribute 'default_directory'

# Fixed code
def write(self, root, sentinels=True):
    """Write a 4.x derived file.
    root is the position of an @<file> node.
    sentinels will be False for @clean and @nosent nodes.
    """
    at, c = self, self.c
    try:
        c.endEditing()
        fileName = at.initWriteIvars(
            root, root.anyAtFileNodeName(), sentinels=sentinels
        )
        if not fileName or not at.precheck(fileName, root):
            if sentinels:
                # Raise dialog warning of data loss.
                at.addToOrphanList(root)
            else:
                # #1450: No danger of data loss.
                pass
            return
        at.openOutputStream()
        at.putFile(root, sentinels=sentinels)
        at.warnAboutOrphandAndIgnoredNodes()
        contents = at.closeOutputStream()
        if at.errors:
            g.es("not written:", g.shortFileName(fileName))
            at.addToOrphanList(root)
        else:
            at.replaceFile(contents, at.encoding, fileName, root)
    except Exception:
        if hasattr(self.root.v, "tnodeList"):
            delattr(self.root.v, "tnodeList")
        at.writeException(fileName, root)
# Buggy code
def get(self, key, default=None):
    if not self.has_key(key):
        return default
    try:
        val = self[key]
        return val
    except KeyError:
        return default


# Traceback (ModuleNotFoundError)
hook failed: after-create-leo-frame2, <bound method FreeLayoutController.loadLayouts of <leo.plugins.free_layout.FreeLayoutController object at 0x00000248F6C65548>>, <no module>
Traceback (most recent call last):

File "C:\Documents and Settings\tom\leo-editor\leo\core\leoPlugins.py", line 324, in callTagHandler
result = handler(tag, keywords)

File "C:\Documents and Settings\tom\leo-editor\leo\plugins\free_layout.py", line 213, in loadLayouts
d = g.app.db.get('ns_layouts') or {}

File "C:\Documents and Settings\tom\leo-editor\leo\core\leoCache.py", line 607, in get
val = self[key]

File "C:\Documents and Settings\tom\leo-editor\leo\core\leoCache.py", line 522, in __getitem__
obj = self.loader(row[0])

File "C:\Documents and Settings\tom\leo-editor\leo\core\leoCache.py", line 483, in loadz
val = pickle.loads(zlib.decompress(data))

ModuleNotFoundError: No module named 'PyQt4'

# Fixed code
def get(self, key, default=None):
    if not self.has_key(key):
        return default
    try:
        val = self[key]
        return val
    except Exception:  # #1444: Was KeyError.
        return default
# Buggy code
def computeWorkbookFileName(self):
    """
    Return the name of the workbook.

    Return None *only* if:
    1. The workbook does not exist.
    2. We are unit testing or in batch mode.
    """
    # lm = self
    fn = g.app.config.getString(setting="default_leo_file")
    # The default is ~/.leo/workbook.leo
    if not fn:
        fn = g.os_path_finalize("~/.leo/workbook.leo")
    fn = g.os_path_finalize(fn)
    if not fn:
        return None
    if g.os_path_exists(fn):
        return fn
    if g.unitTesting or g.app.batchMode:
        # 2017/02/18: unit tests must not create a workbook.
        # Neither should batch mode operation.
        return None
    if g.os_path_isabs(fn):
        # Create the file.
        g.error("Using default leo file name:\n%s" % (fn))
        return fn
    # It's too risky to open a default file if it is relative.
    return None


# Traceback (FileNotFoundError)
unexpected exception loading session
Traceback (most recent call last):

File "c:\users\viktor\pyve\github\leo-dev-opt-b\devel\leo-editor-devel\leo\core\leoApp.py", line 2601, in doPostPluginsInit
g.app.sessionManager.load_session(c1, aList)

[...]

File "c:\users\viktor\pyve\github\leo-dev-opt-b\devel\leo-editor-devel\leo\core\leoApp.py", line 1478, in <listcomp>
if [x for x in aList if os.path.samefile(x, fn)]:

File "C:\EE\Python\lib\genericpath.py", line 96, in samefile
s1 = os.stat(f1)

FileNotFoundError: [WinError 3] Das System kann den angegebenen Pfad nicht finden: 'C:/users/viktor/pyve/ve4ileo/lib/site-packages/leo/doc/quickstart.leo'

# Fixed code
def computeWorkbookFileName(self):
    """
    Return full path to the workbook.

    Return None if testing, or in batch mode, or if the containing
    directory does not exist.
    """
    # lm = self
    # Never create a workbook during unit tests or in batch mode.
    if g.unitTesting or g.app.batchMode:
        return None
    fn = g.app.config.getString(setting="default_leo_file") or "~/.leo/workbook.leo"
    fn = g.os_path_finalize(fn)
    directory = g.os_path_finalize(os.path.dirname(fn))
    # #1415.
    return fn if os.path.exists(directory) else None
# Buggy code
def blacken_node(self, root, diff_flag, check_flag=False):
    """Run black on all Python @<file> nodes in root's tree."""
    c = self.c
    if not black or not root:
        return
    t1 = time.clock()
    self.changed, self.errors, self.total = 0, 0, 0
    self.undo_type = "blacken-node"
    self.blacken_node_helper(root, check_flag, diff_flag)
    t2 = time.clock()
    if not g.unitTesting:
        print(
            f"{root.h}: scanned {self.total} node{g.plural(self.total)}, "
            f"changed {self.changed} node{g.plural(self.changed)}, "
            f"{self.errors} error{g.plural(self.errors)} "
            f"in {t2 - t1:5.2f} sec."
        )
    if self.changed or self.errors:
        c.redraw()


# Traceback (AttributeError)
Traceback (most recent call last):
File "C:\leo-editor\launchLeo.py", line 8, in <module>
leo.core.runLeo.run()
File "C:\leo-editor\leo\core\runLeo.py", line 73, in run
g.app.loadManager.load(fileName, pymacs)
File "C:\leo-editor\leo\core\leoApp.py", line 2392, in load
t1 = time.clock()
AttributeError: module 'time' has no attribute 'clock'

# Fixed code
def blacken_node(self, root, diff_flag, check_flag=False):
    """Run black on all Python @<file> nodes in root's tree."""
    c = self.c
    if not black or not root:
        return
    t1 = time.process_time()
    self.changed, self.errors, self.total = 0, 0, 0
    self.undo_type = "blacken-node"
    self.blacken_node_helper(root, check_flag, diff_flag)
    t2 = time.process_time()
    if not g.unitTesting:
        print(
            f"{root.h}: scanned {self.total} node{g.plural(self.total)}, "
            f"changed {self.changed} node{g.plural(self.changed)}, "
            f"{self.errors} error{g.plural(self.errors)} "
            f"in {t2 - t1:5.2f} sec."
        )
    if self.changed or self.errors:
        c.redraw()
# Buggy code
def blacken_tree(self, root, diff_flag, check_flag=False):
    """Run black on all Python @<file> nodes in root's tree."""
    c = self.c
    if not black or not root:
        return
    t1 = time.clock()
    self.changed, self.errors, self.total = 0, 0, 0
    undo_type = "blacken-tree"
    bunch = c.undoer.beforeChangeTree(root)
    # Blacken *only* the selected tree.
    changed = False
    for p in root.self_and_subtree():
        if self.blacken_node_helper(p, check_flag, diff_flag):
            changed = True
    if changed:
        c.setChanged(True)
        c.undoer.afterChangeTree(root, undo_type, bunch)
    t2 = time.clock()
    if not g.unitTesting:
        print(
            f"{root.h}: scanned {self.total} node{g.plural(self.total)}, "
            f"changed {self.changed} node{g.plural(self.changed)}, "
            f"{self.errors} error{g.plural(self.errors)} "
            f"in {t2 - t1:5.2f} sec."
        )
    if self.changed and not c.changed:
        c.setChanged(True)
    if self.changed or self.errors:
        c.redraw()


# Traceback (AttributeError)
Traceback (most recent call last):
File "C:\leo-editor\launchLeo.py", line 8, in <module>
leo.core.runLeo.run()
File "C:\leo-editor\leo\core\runLeo.py", line 73, in run
g.app.loadManager.load(fileName, pymacs)
File "C:\leo-editor\leo\core\leoApp.py", line 2392, in load
t1 = time.clock()
AttributeError: module 'time' has no attribute 'clock'

# Fixed code
def blacken_tree(self, root, diff_flag, check_flag=False):
    """Run black on all Python @<file> nodes in root's tree."""
    c = self.c
    if not black or not root:
        return
    t1 = time.process_time()
    self.changed, self.errors, self.total = 0, 0, 0
    undo_type = "blacken-tree"
    bunch = c.undoer.beforeChangeTree(root)
    # Blacken *only* the selected tree.
    changed = False
    for p in root.self_and_subtree():
        if self.blacken_node_helper(p, check_flag, diff_flag):
            changed = True
    if changed:
        c.setChanged(True)
        c.undoer.afterChangeTree(root, undo_type, bunch)
    t2 = time.process_time()
    if not g.unitTesting:
        print(
            f"{root.h}: scanned {self.total} node{g.plural(self.total)}, "
            f"changed {self.changed} node{g.plural(self.changed)}, "
            f"{self.errors} error{g.plural(self.errors)} "
            f"in {t2 - t1:5.2f} sec."
        )
    if self.changed and not c.changed:
        c.setChanged(True)
    if self.changed or self.errors:
        c.redraw()
# Buggy code
def createActualFile(self, fileName, toOPML, toZip):
    if toZip:
        self.toString = True
        theActualFile = None
    else:
        try:
            # 2010/01/21: always write in binary mode.
            theActualFile = open(fileName, "wb")
        except IOError:
            g.es(f"can not open {fileName}")
            g.es_exception()
            theActualFile = None
    return fileName, theActualFile


# Traceback (FileNotFoundError)
Traceback (most recent call last):

File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 1599, in createActualFile
theActualFile = open(fileName, 'wb')

FileNotFoundError: [Errno 2] No such file or directory: 'c:/leo.repo/leo-editor/~/.leo/workbook.leo'

# Fixed code
def createActualFile(self, fileName, toOPML, toZip):
    if toZip:
        self.toString = True
        theActualFile = None
    else:
        try:
            # 2010/01/21: always write in binary mode.
            theActualFile = open(fileName, "wb")
        except Exception:
            g.es(f"can not create {fileName}")
            g.es_exception()
            theActualFile = None
    return fileName, theActualFile
# Buggy code
def os_path_finalize(path, **keys):
    """
    Expand '~', then return os.path.normpath, os.path.abspath of the path.
    There is no corresponding os.path method
    """
    path = path.replace("\x00", "")  # Fix Pytyon 3 bug on Windows 10.
    path = os.path.abspath(path)
    path = os.path.normpath(path)
    if g.isWindows:
        path = path.replace("\\", "/")
    # calling os.path.realpath here would cause problems in some situations.
    return path


# Traceback (FileNotFoundError)
Traceback (most recent call last):

File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 1599, in createActualFile
theActualFile = open(fileName, 'wb')

FileNotFoundError: [Errno 2] No such file or directory: 'c:/leo.repo/leo-editor/~/.leo/workbook.leo'

# Fixed code
def os_path_finalize(path):
    """
    Expand '~', then return os.path.normpath, os.path.abspath of the path.
    There is no corresponding os.path method
    """
    path = path.replace("\x00", "")  # Fix Pytyon 3 bug on Windows 10.
    path = os.path.expanduser(path)  # #
    path = os.path.abspath(path)
    path = os.path.normpath(path)
    if g.isWindows:
        path = path.replace("\\", "/")
    # calling os.path.realpath here would cause problems in some situations.
    return path
# Buggy code
def find_git_working_directory(self, directory):
    """Return the git working directory, starting at directory."""
    assert directory
    while directory:
        if g.os_path_exists(g.os_path_finalize_join(directory, ".git")):
            return directory
        path2 = g.os_path_finalize_join(directory, "..")
        if path2 == directory:
            break
        directory = path2
    return None


# Traceback (AssertionError)
Traceback (most recent call last):

File "c:\leo.repo\leo-editor\leo\core\leoGlobals.py", line 320, in new_cmd_wrapper
func(self, event=event)

File "c:\leo.repo\leo-editor\leo\commands\editFileCommands.py", line 342, in gitDiff
GitDiffController(c=self.c).git_diff(rev1='HEAD')

File "c:\leo.repo\leo-editor\leo\commands\editFileCommands.py", line 584, in git_diff
ok = self.diff_revs(rev1, rev2)

File "c:\leo.repo\leo-editor\leo\commands\editFileCommands.py", line 604, in diff_revs
self.diff_file(fn=fn, rev1=rev1, rev2=rev2)

File "c:\leo.repo\leo-editor\leo\commands\editFileCommands.py", line 634, in diff_file
c1 = self.make_at_clean_outline(fn, root, s1, rev1)

File "c:\leo.repo\leo-editor\leo\commands\editFileCommands.py", line 807, in make_at_clean_outline
assert old_public_lines

AssertionError

# Fixed code
def find_git_working_directory(self, directory):
    """Return the git working directory, starting at directory."""
    while directory:
        if g.os_path_exists(g.os_path_finalize_join(directory, ".git")):
            return directory
        path2 = g.os_path_finalize_join(directory, "..")
        if path2 == directory:
            break
        directory = path2
    return None
# Buggy code
def scan(self, s, parent):
    """Create an outline from a MindMap (.csv) file."""
    # pylint: disable=no-member
    # pylint confuses this module with the stdlib json module
    c, d, self.gnx_dict = self.c, json.loads(s), {}
    for d2 in d.get("nodes", []):
        gnx = d2.get("gnx")
        self.gnx_dict[gnx] = d2
    top_d = d.get("top")
    if top_d:
        # Don't set parent.h or parent.gnx or parent.v.u.
        parent.b = top_d.get("b") or ""
        self.create_nodes(parent, top_d)
        c.redraw()
    return bool(top_d)


# Traceback (AttributeError)
Exception running JSON_Scanner
Traceback (most recent call last):

File "/home/dalcolmo/bin/leo-editor/leo/core/leoApp.py", line 1530, in scanner_for_ext_cb
return scanner.run(s, parent)

File "/home/dalcolmo/bin/leo-editor/leo/plugins/importers/leo_json.py", line 61, in run
ok = self.scan(s, parent)

File "/home/dalcolmo/bin/leo-editor/leo/plugins/importers/leo_json.py", line 130, in scan
for d2 in d.get('nodes', []):

AttributeError: 'list' object has no attribute 'get'

# Fixed code
def scan(self, s, parent):
    """Create an outline from a MindMap (.csv) file."""
    # pylint: disable=no-member
    # pylint confuses this module with the stdlib json module
    c, d, self.gnx_dict = self.c, json.loads(s), {}
    try:
        for d2 in d.get("nodes", []):
            gnx = d2.get("gnx")
            self.gnx_dict[gnx] = d2
        top_d = d.get("top")
        if top_d:
            # Don't set parent.h or parent.gnx or parent.v.u.
            parent.b = top_d.get("b") or ""
            self.create_nodes(parent, top_d)
            c.redraw()
    except AttributeError:
        # Partial fix for #1098: issue advice.
        g.error("Can not import %s" % parent.h)
        g.es("Leo can only read .json files that Leo itself wrote")
        g.es("Workaround: copy your .json text into @auto x.json.")
        g.es("Leo will read the file correctly when you reload your outline.")
    return bool(top_d)
# Buggy code
def scan(self, s, parent):
    """Create an outline from a MindMap (.csv) file."""
    # pylint: disable=no-member
    # pylint confuses this module with the stdlib json module
    c, d, self.gnx_dict = self.c, json.loads(s), {}
    try:
        for d2 in d.get("nodes", []):
            gnx = d2.get("gnx")
            self.gnx_dict[gnx] = d2
        top_d = d.get("top")
        if top_d:
            # Don't set parent.h or parent.gnx or parent.v.u.
            parent.b = top_d.get("b") or ""
            self.create_nodes(parent, top_d)
            c.redraw()
    except AttributeError:
        # Partial fix for #1098: issue advice.
        g.error("Can not import %s" % parent.h)
        g.es("Leo can only read .json files that Leo itself wrote")
        g.es("Workaround: copy your .json text into @auto x.json.")
        g.es("Leo will read the file correctly when you reload your outline.")
    return bool(top_d)


# Traceback (AttributeError)
Exception running JSON_Scanner
Traceback (most recent call last):

File "/home/dalcolmo/bin/leo-editor/leo/core/leoApp.py", line 1530, in scanner_for_ext_cb
return scanner.run(s, parent)

File "/home/dalcolmo/bin/leo-editor/leo/plugins/importers/leo_json.py", line 61, in run
ok = self.scan(s, parent)

File "/home/dalcolmo/bin/leo-editor/leo/plugins/importers/leo_json.py", line 130, in scan
for d2 in d.get('nodes', []):

AttributeError: 'list' object has no attribute 'get'

# Fixed code
def scan(self, s, parent):
    """Create an outline from a MindMap (.csv) file."""
    # pylint: disable=no-member
    # pylint confuses this module with the stdlib json module
    c, d, self.gnx_dict = self.c, json.loads(s), {}
    try:
        for d2 in d.get("nodes", []):
            gnx = d2.get("gnx")
            self.gnx_dict[gnx] = d2
        top_d = d.get("top")
        if top_d:
            # Don't set parent.h or parent.gnx or parent.v.u.
            parent.b = top_d.get("b") or ""
            self.create_nodes(parent, top_d)
            c.redraw()
        return bool(top_d)
    except AttributeError:
        # Fix #1098
        c = self.c
        parent.b = repr(d)
        c.redraw()
        return True
# Buggy code
def getTextFromClipboard(self):
    """Get a unicode string from the clipboard."""
    root = Tk()
    root.withdraw()
    try:
        s = root.clipboard_get()
    except Exception:  # _tkinter.TclError:
        s = ""
    root.destroy()
    return g.toUnicode(s)


# Traceback (_tkinter.TclError)
./launchLeo-console.py

import-jupyter-notebook requires nbformat package
setting leoID from os.getenv('USER'): 'benoit'
reading settings in /home/benoit/opt/leo-editor/leo/config/leoSettings.leo
loading npyscreen

Leo 5.8 b1, build 20180815095610, Wed, Aug 15, 2018  9:56:10 AM
Git repo info: branch = master, commit = 6a9b1c0d2909
Python 2.7.15, LeoGui: dummy version
linux2
** isPython3: False

Traceback (most recent call last):
File "./launchLeo-console.py", line 8, in <module>
leo.core.runLeo.run_console()
File "/home/benoit/opt/leo-editor/leo/core/runLeo.py", line 78, in run_console
run(*args, **keywords)
File "/home/benoit/opt/leo-editor/leo/core/runLeo.py", line 72, in run
g.app.loadManager.load(fileName, pymacs)
File "/home/benoit/opt/leo-editor/leo/core/leoApp.py", line 2246, in load
ok = lm.doPostPluginsInit()
File "/home/benoit/opt/leo-editor/leo/core/leoApp.py", line 2300, in doPostPluginsInit
c1 = lm.openEmptyWorkBook()
File "/home/benoit/opt/leo-editor/leo/core/leoApp.py", line 2347, in openEmptyWorkBook
old_clipboard = g.app.gui.getTextFromClipboard()
File "/home/benoit/opt/leo-editor/leo/plugins/cursesGui2.py", line 1608, in getTextFromClipboard
root = Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1822, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

# Fixed code
def getTextFromClipboard(self):
    """Get a unicode string from the clipboard."""
    # Fix #971.
    if not Tk:
        return g.u("")
    root = Tk()
    root.withdraw()
    try:
        s = root.clipboard_get()
    except Exception:  # _tkinter.TclError:
        s = ""
    root.destroy()
    return g.toUnicode(s)
# Buggy code
def replaceClipboardWith(self, s):
    """Replace the clipboard with the string s."""
    root = Tk()
    root.withdraw()
    root.clipboard_clear()
    root.clipboard_append(s)
    root.destroy()


# Traceback (_tkinter.TclError)
./launchLeo-console.py

import-jupyter-notebook requires nbformat package
setting leoID from os.getenv('USER'): 'benoit'
reading settings in /home/benoit/opt/leo-editor/leo/config/leoSettings.leo
loading npyscreen

Leo 5.8 b1, build 20180815095610, Wed, Aug 15, 2018  9:56:10 AM
Git repo info: branch = master, commit = 6a9b1c0d2909
Python 2.7.15, LeoGui: dummy version
linux2
** isPython3: False

Traceback (most recent call last):
File "./launchLeo-console.py", line 8, in <module>
leo.core.runLeo.run_console()
File "/home/benoit/opt/leo-editor/leo/core/runLeo.py", line 78, in run_console
run(*args, **keywords)
File "/home/benoit/opt/leo-editor/leo/core/runLeo.py", line 72, in run
g.app.loadManager.load(fileName, pymacs)
File "/home/benoit/opt/leo-editor/leo/core/leoApp.py", line 2246, in load
ok = lm.doPostPluginsInit()
File "/home/benoit/opt/leo-editor/leo/core/leoApp.py", line 2300, in doPostPluginsInit
c1 = lm.openEmptyWorkBook()
File "/home/benoit/opt/leo-editor/leo/core/leoApp.py", line 2347, in openEmptyWorkBook
old_clipboard = g.app.gui.getTextFromClipboard()
File "/home/benoit/opt/leo-editor/leo/plugins/cursesGui2.py", line 1608, in getTextFromClipboard
root = Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1822, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

# Fixed code
def replaceClipboardWith(self, s):
    """Replace the clipboard with the string s."""
    if not Tk:
        return
    root = Tk()
    root.withdraw()
    root.clipboard_clear()
    root.clipboard_append(s)
    root.destroy()
# Buggy code
def configuredcommands_rclick(c, p, menu):
    """Provide "edit in EDITOR" context menu item"""
    config = c.config.getData("contextmenu_commands")
    if config:
        cmds = [el.split(None, 1) for el in config]
        for cmd, desc in cmds:
            desc = desc.strip()
            action = menu.addAction(desc)

            # action.setToolTip(cmd)
            def create_callback(cm):
                return lambda: c.k.simulateCommand(cm)

            configcmd_rclick_cb = create_callback(cmd)
            action.triggered.connect(configcmd_rclick_cb)


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/jnicoll/leo-editor/leo/plugins/qt_tree.py", line 732, in onContextMenu
h(c, p, menu)
File "/home/jnicoll/leo-editor/leo/plugins/contextmenu.py", line 109, in configuredcommands_rclick
for cmd, desc in cmds:
ValueError: need more than 1 value to unpack
Aborted (core dumped)

# Fixed code
def configuredcommands_rclick(c, p, menu):
    """Provide "edit in EDITOR" context menu item"""
    config = c.config.getData("contextmenu_commands")
    if config:
        cmds = [el.split(None, 1) for el in config]
        for data in cmds:
            # Fix #1084
            try:
                cmd, desc = data
            except ValueError:
                g.es_print("Invalid @data contextmenu_commands")
                continue
            desc = desc.strip()
            action = menu.addAction(desc)

            # action.setToolTip(cmd)
            def create_callback(cm):
                return lambda: c.k.simulateCommand(cm)

            configcmd_rclick_cb = create_callback(cmd)
            action.triggered.connect(configcmd_rclick_cb)
# Buggy code
def onContextMenu(self, point):
    c = self.c
    w = self.treeWidget
    handlers = g.tree_popup_handlers
    menu = QtWidgets.QMenu()
    menuPos = w.mapToGlobal(point)
    if not handlers:
        menu.addAction("No popup handlers")
    p = c.p.copy()
    done = set()
    for h in handlers:
        # every handler has to add it's QActions by itself
        if h in done:
            # do not run the same handler twice
            continue
        h(c, p, menu)
    menu.popup(menuPos)
    self._contextmenu = menu


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/jnicoll/leo-editor/leo/plugins/qt_tree.py", line 732, in onContextMenu
h(c, p, menu)
File "/home/jnicoll/leo-editor/leo/plugins/contextmenu.py", line 109, in configuredcommands_rclick
for cmd, desc in cmds:
ValueError: need more than 1 value to unpack
Aborted (core dumped)

# Fixed code
def onContextMenu(self, point):
    c = self.c
    w = self.treeWidget
    handlers = g.tree_popup_handlers
    menu = QtWidgets.QMenu()
    menuPos = w.mapToGlobal(point)
    if not handlers:
        menu.addAction("No popup handlers")
    p = c.p.copy()
    done = set()
    for handler in handlers:
        # every handler has to add it's QActions by itself
        if handler in done:
            # do not run the same handler twice
            continue
        try:
            handler(c, p, menu)
        except Exception:
            g.es_print("Exception executing right-click handler")
            g.es_exception()
    menu.popup(menuPos)
    self._contextmenu = menu
# Buggy code
def readFile(self, path=None, s=None):
    if not s:
        with open(path, "rb") as f:
            s = f.read()
    return self.readWithElementTree(path, s)


# Traceback (KeyError)
Traceback (most recent call last):
File "c:\leo.repo\leo-editor\launchLeo.py", line 8, in <module>
leo.core.runLeo.run()
File "c:\leo.repo\leo-editor\leo\core\runLeo.py", line 72, in run
g.app.loadManager.load(fileName, pymacs)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2262, in load
lm.doPrePluginsInit(fileName, pymacs)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2432, in doPrePluginsInit
lm.readGlobalSettingsFiles()
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2202, in readGlobalSettingsFiles
theme_path = lm.computeThemeFilePath()
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 1845, in computeThemeFilePath
theme_c = lm.openSettingsFile(path)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2171, in openSettingsFile
readAtFileNodesFlag=False, silent=True)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 653, in openLeoFile
silent=silent,
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 516, in getLeoFile
v = FastRead(c, self.gnxDict).readFile(fileName)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 68, in readFile
return self.readWithElementTree(path, s)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 91, in readWithElementTree
hidden_v = self.scanVnodes(gnx2body, self.gnx2vnode, gnx2ua, v_elements)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 312, in scanVnodes
v_element_visitor(v_elements, hidden_v)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 302, in v_element_visitor
v_element_visitor(e, v)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 302, in v_element_visitor
v_element_visitor(e, v)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 246, in v_element_visitor
gnx = e.attrib['t']
KeyError: 't'

# Fixed code
def readFile(self, path=None, s=None):
    if not s:
        with open(path, "rb") as f:
            s = f.read()
    s = s.replace(b"\x0c", b"")
    # Fix #1036.
    return self.readWithElementTree(path, s)
# Buggy code
def readFile(self, path=None, s=None):
    if not s:
        with open(path, "rb") as f:
            s = f.read()
    s = s.replace(b"\x0c", b"")
    # Fix #1036.
    return self.readWithElementTree(path, s)


# Traceback (KeyError)
Traceback (most recent call last):
File "c:\leo.repo\leo-editor\launchLeo.py", line 8, in <module>
leo.core.runLeo.run()
File "c:\leo.repo\leo-editor\leo\core\runLeo.py", line 72, in run
g.app.loadManager.load(fileName, pymacs)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2262, in load
lm.doPrePluginsInit(fileName, pymacs)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2432, in doPrePluginsInit
lm.readGlobalSettingsFiles()
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2202, in readGlobalSettingsFiles
theme_path = lm.computeThemeFilePath()
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 1845, in computeThemeFilePath
theme_c = lm.openSettingsFile(path)
File "c:\leo.repo\leo-editor\leo\core\leoApp.py", line 2171, in openSettingsFile
readAtFileNodesFlag=False, silent=True)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 653, in openLeoFile
silent=silent,
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 516, in getLeoFile
v = FastRead(c, self.gnxDict).readFile(fileName)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 68, in readFile
return self.readWithElementTree(path, s)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 91, in readWithElementTree
hidden_v = self.scanVnodes(gnx2body, self.gnx2vnode, gnx2ua, v_elements)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 312, in scanVnodes
v_element_visitor(v_elements, hidden_v)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 302, in v_element_visitor
v_element_visitor(e, v)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 302, in v_element_visitor
v_element_visitor(e, v)
File "c:\leo.repo\leo-editor\leo\core\leoFileCommands.py", line 246, in v_element_visitor
gnx = e.attrib['t']
KeyError: 't'

# Fixed code
def readFile(self, path=None, s=None):
    if not s:
        with open(path, "rb") as f:
            s = f.read()
    # s = s.replace(b'\x0c', b'').replace(b'0x00', b'')
    s = s.translate(None, self.translate_table)
    # Fix #1036 and #1046.
    return self.readWithElementTree(path, s)
# Buggy code
def git_version(file):
    """Fetch from Git: {tag} {distance-from-tag} {current commit hash}
    Return as semantic version string compliant with PEP440"""
    root = os.path.dirname(os.path.realpath(file))
    try:
        tag, distance, commit = g.gitDescribe(root)
        # 5.6b2, 55, e1129da
        ctag = clean_git_tag(tag)
        # version = get_semver(ctag)
        version = ctag
        if int(distance) > 0:
            version = "{}-dev{}".format(version, distance)
    except IndexError:
        version = None
    return version


# Traceback (FileNotFoundError)
pip install .
Processing d:\matt\code\leo-build
Installing build dependencies ... done
Complete output from command python setup.py egg_info:

Removing build, dist and egg directories
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Matt\AppData\Local\Temp\pip-req-build-vau006t6\setup.py", line 166, in <module>
version=get_version(__file__),
File "C:\Users\Matt\AppData\Local\Temp\pip-req-build-vau006t6\setup.py", line 32, in get_version
version = git_version(file)
File "C:\Users\Matt\AppData\Local\Temp\pip-req-build-vau006t6\setup.py", line 42, in git_version
tag, distance, commit = g.gitDescribe(root)
File "C:\Users\Matt\AppData\Local\Temp\pip-req-build-vau006t6\leo\core\leoGlobals.py", line 4887, in gitDescribe
describe = g.execGitCommand('git describe --tags --long', path)
File "C:\Users\Matt\AppData\Local\Temp\pip-req-build-vau006t6\leo\core\leoGlobals.py", line 4690, in execGitCommand
shell=False,
File "c:\apps\Miniconda3\envs\leo-build\lib\subprocess.py", line 769, in __init__
restore_signals, start_new_session)
File "c:\apps\Miniconda3\envs\leo-build\lib\subprocess.py", line 1172, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Matt\AppData\Local\Temp\pip-req-build-vau006t6\

# Fixed code
def git_version(file, version=None):
    """Fetch from Git: {tag} {distance-from-tag} {current commit hash}
    Return as semantic version string compliant with PEP440"""
    root = os.path.dirname(os.path.realpath(file))
    try:
        tag, distance, commit = g.gitDescribe(root)
        # 5.6b2, 55, e1129da
        ctag = clean_git_tag(tag)
        # version = get_semver(ctag)
        version = ctag
        if int(distance) > 0:
            version = "{}-dev{}".format(version, distance)
    except IndexError:
        print("Attempt to `git describe` failed with IndexError")
    except FileNotFoundError:
        print("Attempt to `git describe` failed with FileNotFoundError")
    return version
# Buggy code
def get_version(file, version=None):
    """Determine current Leo version. Use git if in checkout, else internal Leo"""
    root = os.path.dirname(os.path.realpath(file))
    if os.path.exists(os.path.join(root, ".git")):
        version = git_version(file)
    else:
        version = get_semver(leoVersion.version)
    return version


# Traceback (ModuleNotFoundError)
(leo-next) PS C:\Users\Viktor\leo-next> pip install https://github.com/leo-editor/leo-editor/archive/master.zip
Collecting https://github.com/leo-editor/leo-editor/archive/master.zip
Downloading https://github.com/leo-editor/leo-editor/archive/master.zip
- 11.5MB 1.3MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\setup.py", line 10, in <module>
import semantic_version
ModuleNotFoundError: No module named 'semantic_version'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\
(leo-next) PS C:\Users\Viktor\leo-next>

# Fixed code
def get_version(file, version=None):
    """Determine current Leo version. Use git if in checkout, else internal Leo"""
    root = os.path.dirname(os.path.realpath(file))
    if os.path.exists(os.path.join(root, ".git")):
        version = git_version(file)
    else:
        version = get_semver(leoVersion.version)
    if not version:
        version = leoVersion.version
    return version
# Buggy code
def get_semver(tag):
    """Return 'Semantic Version' from tag string"""
    try:
        version = str(semantic_version.Version.coerce(tag, partial=True))
        # tuple of major, minor, build, pre-release, patch
        # 5.6b2 --> 5.6-b2
    except ValueError:
        print(
            """*** Failed to parse Semantic Version from git tag '{0}'.
        Expecting tag name like '5.7b2', 'leo-4.9.12', 'v4.3' for releases.
        This version can't be uploaded to PyPi.org.""".format(tag)
        )
        version = tag
    return version


# Traceback (ModuleNotFoundError)
(leo-next) PS C:\Users\Viktor\leo-next> pip install https://github.com/leo-editor/leo-editor/archive/master.zip
Collecting https://github.com/leo-editor/leo-editor/archive/master.zip
Downloading https://github.com/leo-editor/leo-editor/archive/master.zip
- 11.5MB 1.3MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\setup.py", line 10, in <module>
import semantic_version
ModuleNotFoundError: No module named 'semantic_version'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\
(leo-next) PS C:\Users\Viktor\leo-next>

# Fixed code
def get_semver(tag):
    """Return 'Semantic Version' from tag string"""
    try:
        import semantic_version

        version = str(semantic_version.Version.coerce(tag, partial=True))
        # tuple of major, minor, build, pre-release, patch
        # 5.6b2 --> 5.6-b2
    except ImportError or ValueError:
        print(
            """*** Failed to parse Semantic Version from git tag '{0}'.
        Expecting tag name like '5.7b2', 'leo-4.9.12', 'v4.3' for releases.
        This version can't be uploaded to PyPi.org.""".format(tag)
        )
        version = tag
    return version
# Buggy code
def get_semver(tag):
    """Return 'Semantic Version' from tag string"""
    try:
        import semantic_version

        version = str(semantic_version.Version.coerce(tag, partial=True))
        # tuple of major, minor, build, pre-release, patch
        # 5.6b2 --> 5.6-b2
    except ImportError or ValueError:
        print(
            """*** Failed to parse Semantic Version from git tag '{0}'.
        Expecting tag name like '5.7b2', 'leo-4.9.12', 'v4.3' for releases.
        This version can't be uploaded to PyPi.org.""".format(tag)
        )
        version = tag
    return version


# Traceback (ModuleNotFoundError)
(leo-next) PS C:\Users\Viktor\leo-next> pip install https://github.com/leo-editor/leo-editor/archive/master.zip
Collecting https://github.com/leo-editor/leo-editor/archive/master.zip
Downloading https://github.com/leo-editor/leo-editor/archive/master.zip
- 11.5MB 1.3MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\setup.py", line 10, in <module>
import semantic_version
ModuleNotFoundError: No module named 'semantic_version'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\
(leo-next) PS C:\Users\Viktor\leo-next>

# Fixed code
def get_semver(tag):
    """Return 'Semantic Version' from tag string"""
    try:
        import semantic_version

        version = str(semantic_version.Version.coerce(tag, partial=True))
        # tuple of major, minor, build, pre-release, patch
        # 5.6b2 --> 5.6-b2
    except ImportError or ValueError as err:
        print("\n", err)
        print(
            """*** Failed to parse Semantic Version from git tag '{0}'.
        Expecting tag name like '5.7b2', 'leo-4.9.12', 'v4.3' for releases.
        This version can't be uploaded to PyPi.org.""".format(tag)
        )
        version = tag
    return version
# Buggy code
def clean():
    print("Removing build and dist directories")
    root = os.path.dirname(os.path.realpath(__file__))
    for d in ["build", "dist", "leo.egg-info"]:
        dpath = os.path.join(root, d)
        if os.path.isdir(dpath):
            rmtree(dpath)


# Traceback (ModuleNotFoundError)
(leo-next) PS C:\Users\Viktor\leo-next> pip install https://github.com/leo-editor/leo-editor/archive/master.zip
Collecting https://github.com/leo-editor/leo-editor/archive/master.zip
Downloading https://github.com/leo-editor/leo-editor/archive/master.zip
- 11.5MB 1.3MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\setup.py", line 10, in <module>
import semantic_version
ModuleNotFoundError: No module named 'semantic_version'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Viktor\AppData\Local\Temp\pip-9ceji4i6-build\
(leo-next) PS C:\Users\Viktor\leo-next>

# Fixed code
def clean():
    print("\nRemoving build, dist and egg directories")
    root = os.path.dirname(os.path.realpath(__file__))
    for d in ["build", "dist", "leo.egg-info", ".eggs"]:
        dpath = os.path.join(root, d)
        if os.path.isdir(dpath):
            rmtree(dpath)
# Buggy code
def checkLinks(self):
    """Check the consistency of all links in the outline."""
    c = self
    t1 = time.time()
    count, errors = 0, 0
    for p in c.safe_all_positions():
        count += 1
        try:
            c.checkThreadLinks(p)
            c.checkSiblings(p)
            c.checkParentAndChildren(p)
        except AssertionError:
            errors += 1
            junk, value, junk = sys.exc_info()
            g.error("test failed at position %s\n%s" % (repr(p), value))
    t2 = time.time()
    g.es_print(
        "check-links: %4.2f sec. %s %s nodes" % (t2 - t1, c.shortFileName(), count),
        color="blue",
    )
    return errors


# Traceback (ValueError)
Traceback (most recent call last):

File "/pri/git/leo-editor/leo/core/leoCommands.py", line 2016, in executeAnyCommand
return command(event)

File "/pri/git/leo-editor/leo/core/leoGlobals.py", line 2445, in commander_command_wrapper
method(event=event)

File "/pri/git/leo-editor/leo/commands/commanderOutlineCommands.py", line 1390, in promote
p.promote()

File "/pri/git/leo-editor/leo/core/leoNodes.py", line 1596, in promote
child.parents.remove(p.v)

ValueError: list.remove(x): x not in list

# Fixed code
def checkLinks(self):
    """Check the consistency of all links in the outline."""
    c = self
    t1 = time.time()
    count, errors = 0, 0
    for p in c.safe_all_positions():
        count += 1
        # try:
        if not c.checkThreadLinks(p):
            errors += 1
            break
        if not c.checkSiblings(p):
            errors += 1
            break
        if not c.checkParentAndChildren(p):
            errors += 1
            break
        # except AssertionError:
        # errors += 1
        # junk, value, junk = sys.exc_info()
        # g.error("test failed at position %s\n%s" % (repr(p), value))
    t2 = time.time()
    g.es_print(
        "check-links: %4.2f sec. %s %s nodes" % (t2 - t1, c.shortFileName(), count),
        color="blue",
    )
    return errors
# Buggy code
def checkSiblings(self, p):
    """Check the consistency of next and back links."""
    back = p.back()
    next = p.next()
    if back:
        assert p == back.next(), "p!=p.back().next(),  back: %s\nback.next: %s" % (
            back,
            back.next(),
        )
    if next:
        assert p == next.back(), "p!=p.next().back, next: %s\nnext.back: %s" % (
            next,
            next.back(),
        )


# Traceback (ValueError)
Traceback (most recent call last):

File "/pri/git/leo-editor/leo/core/leoCommands.py", line 2016, in executeAnyCommand
return command(event)

File "/pri/git/leo-editor/leo/core/leoGlobals.py", line 2445, in commander_command_wrapper
method(event=event)

File "/pri/git/leo-editor/leo/commands/commanderOutlineCommands.py", line 1390, in promote
p.promote()

File "/pri/git/leo-editor/leo/core/leoNodes.py", line 1596, in promote
child.parents.remove(p.v)

ValueError: list.remove(x): x not in list

# Fixed code
def checkSiblings(self, p):
    """Check the consistency of next and back links."""
    back = p.back()
    next = p.next()
    if back:
        if not g._assert(p == back.next()):
            g.trace(
                "p!=p.back().next(),  back: %s\nback.next: %s" % (back, back.next())
            )
            return False
    if next:
        if not g._assert(p == next.back()):
            g.trace("p!=p.next().back, next: %s\nnext.back: %s" % (next, next.back()))
            return False
    return True
# Buggy code
def checkThreadLinks(self, p):
    """Check consistency of threadNext & threadBack links."""
    threadBack = p.threadBack()
    threadNext = p.threadNext()
    if threadBack:
        assert p == threadBack.threadNext(), "p!=p.threadBack().threadNext()"
    if threadNext:
        assert p == threadNext.threadBack(), "p!=p.threadNext().threadBack()"


# Traceback (ValueError)
Traceback (most recent call last):

File "/pri/git/leo-editor/leo/core/leoCommands.py", line 2016, in executeAnyCommand
return command(event)

File "/pri/git/leo-editor/leo/core/leoGlobals.py", line 2445, in commander_command_wrapper
method(event=event)

File "/pri/git/leo-editor/leo/commands/commanderOutlineCommands.py", line 1390, in promote
p.promote()

File "/pri/git/leo-editor/leo/core/leoNodes.py", line 1596, in promote
child.parents.remove(p.v)

ValueError: list.remove(x): x not in list

# Fixed code
def checkThreadLinks(self, p):
    """Check consistency of threadNext & threadBack links."""
    threadBack = p.threadBack()
    threadNext = p.threadNext()
    if threadBack:
        if not g._assert(p == threadBack.threadNext()):
            g.trace("p!=p.threadBack().threadNext()")
            return False
    if threadNext:
        if not g._assert(p == threadNext.threadBack()):
            g.trace("p!=p.threadNext().threadBack()")
            return False
    return True
# Buggy code
def _assert(condition):
    """A safer alternative to a bare assert."""
    if g.unitTesting:
        assert condition
        return
    ok = bool(condition)
    if ok:
        return True
    g.es_print("g._assert failed")
    g.es_print(g.callers())
    return False


# Traceback (ValueError)
Traceback (most recent call last):

File "/pri/git/leo-editor/leo/core/leoCommands.py", line 2016, in executeAnyCommand
return command(event)

File "/pri/git/leo-editor/leo/core/leoGlobals.py", line 2445, in commander_command_wrapper
method(event=event)

File "/pri/git/leo-editor/leo/commands/commanderOutlineCommands.py", line 1390, in promote
p.promote()

File "/pri/git/leo-editor/leo/core/leoNodes.py", line 1596, in promote
child.parents.remove(p.v)

ValueError: list.remove(x): x not in list

# Fixed code
def _assert(condition, show_callers=True):
    """A safer alternative to a bare assert."""
    if g.unitTesting:
        assert condition
        return
    ok = bool(condition)
    if ok:
        return True
    print("")
    g.es_print("===== g._assert failed =====")
    print("")
    if show_callers:
        g.es_print(g.callers())
    return False