# Buggy code
def parse_leo_file(self, theFile, inputFileName, silent, inClipboard, s=None):
    c = self.c
    try:
        if g.isPython3:
            if theFile:
                # Use the open binary file, opened by the caller.
                s = theFile.read()  # isinstance(s, bytes)
                s = self.cleanSaxInputString(s)
                theFile = BytesIO(s)
            else:
                s = str(s, encoding="utf-8")
                s = self.cleanSaxInputString(s)
                theFile = StringIO(s)
        else:
            if theFile:
                s = theFile.read()
            s = self.cleanSaxInputString(s)
            theFile = cStringIO.StringIO(s)
        parser = xml.sax.make_parser()
        parser.setFeature(xml.sax.handler.feature_external_ges, 1)
        # Include external general entities, esp. xml-stylesheet lines.
        if 0:  # Expat does not read external features.
            parser.setFeature(xml.sax.handler.feature_external_pes, 1)
            # Include all external parameter entities
            # Hopefully the parser can figure out the encoding from the <?xml> element.
        # It's very hard to do anything meaningful wih an exception.
        handler = SaxContentHandler(c, inputFileName, silent, inClipboard)
        parser.setContentHandler(handler)
        parser.parse(theFile)  # expat does not support parseString
        # g.trace('parsing done')
        sax_node = handler.getRootNode()
    except Exception:
        g.error("error parsing", inputFileName)
        g.es_exception()
        sax_node = None
    return sax_node


# Traceback (TypeError)
$ python launchLeo.py

setting leoID from os.getenv('USER'): '<user>'
reading settings in /Users/<user>/build-dirs/leo-editor/leo/config/leoSettings.leo
reading settings in /Users/<user>/.leo/myLeoSettings.leo
Using default leo file name:
/Users/<user>/.leo/workbook.leo

** isPython3: True
Leo 5.4, build 20170301100728, Wed Mar  1 10:07:28 CST 2017
Git repo info: branch = master, commit = 8f01f57131ae
Python 3.5.3, PyQt version 5.6.2
darwin
reading settings in /Users/<user>/build-dirs/leo-editor/leo/doc/CheatSheet.leo
wrote recent file: /Users/<user>/.leo/.leoRecentFiles.txt
reading settings in /Users/<user>/.leo/myLeoSettings.leo
read only: unl:///Users/<user>/build-dirs/leo-editor/leo/config/leoSettings.leo
error parsing unl:///Users/<user>/build-dirs/leo-editor/leo/config/leoSettings.leo
Traceback (most recent call last):

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoFileCommands.py", line 1243, in parse_leo_file
s = str(s, encoding='utf-8')

TypeError: coercing to str: need a bytes-like object, NoneType found

exception executing command
Traceback (most recent call last):

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoCommands.py", line 5501, in doCommand
val = command(event)

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoConfig.py", line 2149, in f
self.find_setting(setting)

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoConfig.py", line 2112, in find_setting
unl = self.copy_to_my_settings(unl, which=2)

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoConfig.py", line 2068, in copy_to_my_settings
c2 = g.app.loadManager.openSettingsFile(path)

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoApp.py", line 1903, in openSettingsFile
readAtFileNodesFlag=False, silent=True)

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoFileCommands.py", line 833, in openLeoFile
silent=silent,

File "/Users/<user>/build-dirs/leo-editor/leo/core/leoFileCommands.py", line 698, in getLeoFile
theFile.close()

AttributeError: 'NoneType' object has no attribute 'close'

# Fixed code
def parse_leo_file(self, theFile, inputFileName, silent, inClipboard, s=None):
    c = self.c
    # Fix #434: Potential bug in settings.
    if not theFile and not s:
        return None
    try:
        if g.isPython3:
            if theFile:
                # Use the open binary file, opened by the caller.
                s = theFile.read()  # isinstance(s, bytes)
                s = self.cleanSaxInputString(s)
                theFile = BytesIO(s)
            else:
                s = str(s, encoding="utf-8")
                s = self.cleanSaxInputString(s)
                theFile = StringIO(s)
        else:
            if theFile:
                s = theFile.read()
            s = self.cleanSaxInputString(s)
            theFile = cStringIO.StringIO(s)
        parser = xml.sax.make_parser()
        parser.setFeature(xml.sax.handler.feature_external_ges, 1)
        # Include external general entities, esp. xml-stylesheet lines.
        if 0:  # Expat does not read external features.
            parser.setFeature(xml.sax.handler.feature_external_pes, 1)
            # Include all external parameter entities
            # Hopefully the parser can figure out the encoding from the <?xml> element.
        # It's very hard to do anything meaningful wih an exception.
        handler = SaxContentHandler(c, inputFileName, silent, inClipboard)
        parser.setContentHandler(handler)
        parser.parse(theFile)  # expat does not support parseString
        # g.trace('parsing done')
        sax_node = handler.getRootNode()
    except Exception:
        g.error("error parsing", inputFileName)
        g.es_exception()
        sax_node = None
    return sax_node