# Buggy code
def read_my_cnf_files(self, files, keys):
    """
    Reads a list of config files and merges them. The last one will win.
    :param files: list of files to read
    :param keys: list of keys to retrieve
    :returns: tuple, with None for missing keys.
    """
    cnf = read_config_files(files)

    sections = ["client"]
    if self.login_path and self.login_path != "client":
        sections.append(self.login_path)

    if self.defaults_suffix:
        sections.extend([sect + self.defaults_suffix for sect in sections])

    def get(key):
        result = None
        for sect in cnf:
            if sect in sections and key in cnf[sect]:
                result = cnf[sect][key]
        return result

    return {x: get(x) for x in keys}


# Traceback (TypeError)
2018-07-22 01:30:33,368 (48024/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/mycli/main.py", line 445, in connect
_connect()
File "/usr/local/lib/python3.7/site-packages/mycli/main.py", line 398, in _connect
socket, charset, local_infile, ssl)
File "/usr/local/lib/python3.7/site-packages/mycli/sqlexecute.py", line 52, in __init__
self.connect()
File "/usr/local/lib/python3.7/site-packages/mycli/sqlexecute.py", line 88, in connect
conv=conv, ssl=ssl)
File "/usr/local/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/usr/local/lib/python3.7/site-packages/pymysql/connections.py", line 598, in connect
self._request_authentication()
File "/usr/local/lib/python3.7/site-packages/pymysql/connections.py", line 808, in _request_authentication
authresp = _auth.scramble_native_password(self.password, self.salt)
File "/usr/local/lib/python3.7/site-packages/pymysql/_auth.py", line 31, in scramble_native_password
stage1 = sha1_new(password).digest()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/hashlib.py", line 149, in __hash_new
return _hashlib.new(name, data)
TypeError: object supporting the buffer API required
'

# Fixed code
def read_my_cnf_files(self, files, keys):
    """
    Reads a list of config files and merges them. The last one will win.
    :param files: list of files to read
    :param keys: list of keys to retrieve
    :returns: tuple, with None for missing keys.
    """
    cnf = read_config_files(files)

    sections = ["client"]
    if self.login_path and self.login_path != "client":
        sections.append(self.login_path)

    if self.defaults_suffix:
        sections.extend([sect + self.defaults_suffix for sect in sections])

    def get(key):
        result = None
        for sect in cnf:
            if sect in sections and key in cnf[sect]:
                result = cnf[sect][key]
        # HACK: if result is a list, then ConfigObj() probably decoded from
        # string by splitting on comma, so reconstruct string by joining on
        # comma.
        if isinstance(result, list):
            result = ",".join(result)
        return result

    return {x: get(x) for x in keys}