# Buggy code
def set_user_env(reg, parent=None):
    """Set HKCU (current user) environment variables"""
    reg = listdict2envdict(reg)
    types = dict()
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment")
    for name in reg:
        try:
            _x, types[name] = winreg.QueryValueEx(key, name)
        except WindowsError:
            types[name] = winreg.REG_EXPAND_SZ
    key = winreg.OpenKey(
        winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_SET_VALUE
    )
    for name in reg:
        winreg.SetValueEx(key, name, 0, types[name], reg[name])
    try:
        from win32gui import SendMessageTimeout
        from win32con import HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG

        SendMessageTimeout(
            HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, 5000
        )
    except ImportError:
        QMessageBox.warning(
            parent,
            _("Warning"),
            _(
                "Module <b>pywin32 was not found</b>.<br>"
                "Please restart this Windows <i>session</i> "
                "(not the computer) for changes to take effect."
            ),
        )


# Traceback (TypeError)
File "/home/mhizzani/anaconda3/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/client.py", line 571, in show_env
self.dialog_manager.show(RemoteEnvDialog(env))
File "/home/mhizzani/anaconda3/lib/python3.6/site-packages/spyder/utils/environ.py", line 45, in __init__
self.setup(envdict2listdict(environ),
File "/home/mhizzani/anaconda3/lib/python3.6/site-packages/spyder/utils/environ.py", line 26, in envdict2listdict
for key in envdict:
TypeError: 'NoneType' object is not iterable
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}

# Fixed code
def set_user_env(reg, parent=None):
    """Set HKCU (current user) environment variables"""
    reg = listdict2envdict(reg)
    types = dict()
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment")
    for name in reg:
        try:
            _x, types[name] = winreg.QueryValueEx(key, name)
        except WindowsError:
            types[name] = winreg.REG_EXPAND_SZ
    key = winreg.OpenKey(
        winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_SET_VALUE
    )
    for name in reg:
        winreg.SetValueEx(key, name, 0, types[name], reg[name])
    try:
        from win32gui import SendMessageTimeout
        from win32con import HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG

        SendMessageTimeout(
            HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, 5000
        )
    except Exception:
        QMessageBox.warning(
            parent,
            _("Warning"),
            _(
                "Module <b>pywin32 was not found</b>.<br>"
                "Please restart this Windows <i>session</i> "
                "(not the computer) for changes to take effect."
            ),
        )