# Buggy code
def get_enviroment(self, environment_path=None):
    # TODO(gatesn): #339 - make better use of jedi environments, they seem pretty powerful
    if environment_path is None:
        environment = jedi.api.environment.get_cached_default_environment()
    else:
        if environment_path in self._workspace._environments:
            environment = self._workspace._environments[environment_path]
        else:
            environment = jedi.api.environment.create_environment(
                path=environment_path, safe=False
            )
            self._workspace._environments[environment_path] = environment

    return environment


# Traceback (TypeError)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1440, in handle_go_to_definition
def_range = position['range']
TypeError: list indices must be integers or slices, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\ProgramData\Anaconda3\lib\logging\__init__.py", line 992, in emit
msg = self.format(record)
File "c:\ProgramData\Anaconda3\lib\logging\__init__.py", line 838, in format
return fmt.format(record)
File "c:\ProgramData\Anaconda3\lib\logging\__init__.py", line 575, in format
record.message = record.getMessage()
File "c:\ProgramData\Anaconda3\lib\logging\__init__.py", line 338, in getMessage
msg = msg % self.args
ValueError: incomplete format
Call stack:
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\app\start.py", line 223, in <module>
main()
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\app\start.py", line 219, in main
mainwindow.main()
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3651, in main
mainwindow = run_spyder(app, options, args)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3567, in run_spyder
app.exec_()
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\completion\languageserver\client.py", line 497, in on_msg_received
self.req_reply[req_id](None, {'params': []})
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\completion\languageserver\plugin.py", line 549, in receive_response
self.COMPLETION_CLIENT_NAME, req_id, response)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 123, in receive_response
self.howto_send_to_codeeditor(req_id)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 171, in howto_send_to_codeeditor
self.skip_and_send_to_codeeditor(req_id)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 205, in skip_and_send_to_codeeditor
self.gather_and_send_to_codeeditor(request_responses)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 273, in gather_and_send_to_codeeditor
response_instance.handle_response(req_type, responses)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1019, in handle_response
handler(params)
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1457, in handle_go_to_definition
"Error when processing go to definition")
File "c:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1050, in log_lsp_handle_errors
logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)

# Fixed code
def get_enviroment(self, environment_path=None, env_vars=None):
    # TODO(gatesn): #339 - make better use of jedi environments, they seem pretty powerful
    if environment_path is None:
        environment = jedi.api.environment.get_cached_default_environment()
    else:
        if environment_path in self._workspace._environments:
            environment = self._workspace._environments[environment_path]
        else:
            environment = jedi.api.environment.create_environment(
                path=environment_path, safe=False, env_vars=env_vars
            )
            self._workspace._environments[environment_path] = environment

    return environment