# Buggy code
def makeAllNonExistentDirectories(theDir, c=None, force=False, verbose=True):
    """Attempt to make all non-existent directories"""
    testing = False  # True: don't actually make the directories.
    if force:
        create = True  # Bug fix: g.app.config will not exist during startup.
    elif c:
        create = c.config and c.config.create_nonexistent_directories
    else:
        create = g.app and g.app.config and g.app.config.create_nonexistent_directories
    if c:
        theDir = c.expand_path_expression(theDir)
    dir1 = theDir = g.os_path_normpath(theDir)
    ok = g.os_path_isdir(dir1) and g.os_path_exists(dir1)
    if ok:
        return ok
    if not force and not create:
        return False
    # Split theDir into all its component parts.
    paths = []
    while theDir:
        head, tail = g.os_path_split(theDir)
        if tail:
            paths.append(tail)
            theDir = head
        else:
            paths.append(head)
            break
    path = ""
    paths.reverse()
    for s in paths:
        path = g.os_path_finalize_join(path, s)
        if not g.os_path_exists(path):
            try:
                if testing:
                    g.trace("***making", path)
                else:
                    os.mkdir(path)
                if verbose and not testing and not g.app.unitTesting:
                    g.red("created directory:", path)
            except Exception:
                if verbose:
                    g.error("exception creating directory:", path)
                g.es_exception()
                return None
    return dir1  # All have been created.


# 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 makeAllNonExistentDirectories(theDir, c=None, force=False, verbose=True):
    """
    Attempt to make all non-existent directories.

    A wrapper from os.makedirs (new in Python 3.2).

    """
    if force:
        create = True  # Bug fix: g.app.config will not exist during startup.
    elif c:
        create = c.config and c.config.create_nonexistent_directories
    else:
        create = g.app and g.app.config and g.app.config.create_nonexistent_directories
    if c:
        theDir = c.expand_path_expression(theDir)
    #
    # Return True if the directory already exists.
    dir1 = theDir = g.os_path_normpath(theDir)
    exists = g.os_path_isdir(dir1) and g.os_path_exists(dir1)
    if exists:
        return True
    #
    # Return False if we aren't forcing the create.
    if not force and not create:
        return False
    #
    # Just use os.makedirs.
    try:
        os.makedirs(theDir, mode=0o777, exist_ok=False)
        return True
    except Exception:
        return False