# Buggy code
def reorder_filenames(self, filenames):
    """Take the last session filenames and put the last open on first.

    It takes a list of filenames and using the current filename from the
    layout settings, sets the one that had focused last in the position 0.
    It also reorders the current lines for each file (supposing that they
    are in the same order as the filenames) and sets them back in the
    layout settings.
    """
    layout = self.get_option("layout_settings", None)
    splitsettings = layout.get("splitsettings")
    index_first_file = 0
    reordered_splitsettings = []
    for index, (is_vertical, cfname, clines) in enumerate(splitsettings):
        # the first element of filenames is now the one that last had focus
        if index == 0:
            if cfname in filenames:
                index_first_file = filenames.index(cfname)
                filenames.pop(index_first_file)
                filenames.insert(0, cfname)
            else:
                cfname = filenames[0]
                index_first_file = 0
        if index_first_file != 0:
            clines_0 = clines[0]
            clines.pop(index_first_file)
            clines.insert(0, clines_0)
        reordered_splitsettings.append((is_vertical, cfname, clines))
    layout["splitsettings"] = reordered_splitsettings
    self.set_option("layout_settings", layout)
    return filenames


# Traceback (AttributeError)
File "/usr/lib/python3.6/site-packages/spyder/plugins/projects.py", line 145, in <lambda>
lambda v: self.editor.setup_open_files())
File "/usr/lib/python3.6/site-packages/spyder/plugins/editor.py", line 2707, in setup_open_files
filenames = self.reorder_filenames(filenames)
File "/usr/lib/python3.6/site-packages/spyder/plugins/editor.py", line 2733, in reorder_filenames
splitsettings = layout.get('splitsettings')
AttributeError: 'NoneType' object has no attribute 'get'

# Fixed code
def reorder_filenames(self, filenames):
    """Take the last session filenames and put the last open on first.

    It takes a list of filenames and using the current filename from the
    layout settings, sets the one that had focused last in the position 0.
    It also reorders the current lines for each file (supposing that they
    are in the same order as the filenames) and sets them back in the
    layout settings.
    """
    layout = self.get_option("layout_settings", None)
    if layout is None:
        return filenames
    splitsettings = layout.get("splitsettings")
    index_first_file = 0
    reordered_splitsettings = []
    for index, (is_vertical, cfname, clines) in enumerate(splitsettings):
        # the first element of filenames is now the one that last had focus
        if index == 0:
            if cfname in filenames:
                index_first_file = filenames.index(cfname)
                filenames.pop(index_first_file)
                filenames.insert(0, cfname)
            else:
                cfname = filenames[0]
                index_first_file = 0
        if index_first_file != 0:
            clines_0 = clines[0]
            clines.pop(index_first_file)
            clines.insert(0, clines_0)
        reordered_splitsettings.append((is_vertical, cfname, clines))
    layout["splitsettings"] = reordered_splitsettings
    self.set_option("layout_settings", layout)
    return filenames