Spyder: KeyError in PyLS when getting a hover

Created on 3 Jun 2019  路  10Comments  路  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

I have code that uses Argparse (which I am practicing). When I open Spyder, I run the file. Then I select a variable in the editor, and this error keeps popping up as soon as it is highlighted by Spyder. I restarted Spyder, and the issue seems to persist.

Traceback

  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls_jsonrpc/endpoint.py", line 113, in consume
    self._handle_request(message['id'], message['method'], message.get('params'))
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls_jsonrpc/endpoint.py", line 182, in _handle_request
    handler_result = handler(params)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls_jsonrpc/dispatchers.py", line 23, in handler
    return method(**(params or {}))
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls/python_ls.py", line 271, in m_text_document__hover
    return self.hover(textDocument['uri'], position)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls/python_ls.py", line 215, in hover
    return self._hook('pyls_hover', doc_uri, position=position) or {'contents': ''}
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls/python_ls.py", line 122, in _hook
    return hook_handlers(config=self.config, workspace=self.workspace, document=doc, **kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/_tracing.py", line 80, in __call__
    return outcome.get_result()
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/callers.py", line 52, in from_call
    result = func()
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/_tracing.py", line 78, in <lambda>
    outcome = _Result.from_call(lambda: self.oldcall(hook, hook_impls, kwargs))
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/manager.py", line 62, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/pyls/plugins/hover.py", line 10, in pyls_hover
    definitions = document.jedi_script(position).goto_definitions()
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/api/__init__.py", line 220, in goto_definitions
    definitions = helpers.evaluate_goto_definition(self._evaluator, context, leaf)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/api/helpers.py", line 143, in evaluate_goto_definition
    return evaluator.goto_definitions(context, leaf)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/__init__.py", line 230, in goto_definitions
    return eval_expr_stmt(context, def_, name)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/syntax_tree.py", line 48, in wrapper
    return func(context, *args, **kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/syntax_tree.py", line 284, in eval_expr_stmt
    return _eval_expr_stmt(context, stmt, seek_name)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/debug.py", line 81, in wrapper
    return func(*args, **kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/syntax_tree.py", line 300, in _eval_expr_stmt
    context_set = context.eval_node(rhs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/base_context.py", line 145, in eval_node
    return self.evaluator.eval_element(self, node)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/__init__.py", line 200, in eval_element
    return self._eval_element_if_evaluated(context, element)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/__init__.py", line 212, in _eval_element_if_evaluated
    return self._eval_element_cached(context, element)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/cache.py", line 40, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/__init__.py", line 216, in _eval_element_cached
    return eval_node(context, element)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/debug.py", line 81, in wrapper
    return func(*args, **kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/syntax_tree.py", line 48, in wrapper
    return func(context, *args, **kwargs)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/syntax_tree.py", line 85, in eval_node
    context_set = eval_atom(context, first_child)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/syntax_tree.py", line 262, in eval_atom
    context = iterable.SequenceLiteralContext(context.evaluator, context, atom)
  File "/home/parichay/code/spyderz/spyder4/lib/python3.5/site-packages/jedi/evaluate/context/iterable.py", line 293, in __init__
    self.array_type = SequenceLiteralContext.mapping[atom.children[0]]

Versions

  • Spyder version: 4.0.0b2
  • Python version: 3.5.2
  • Qt version: 5.12.3
  • PyQt5 version: 5.12.2
  • Operating System: Linux 4.4.0-148-generic

Dependencies

pygments >=2.0     :  2.4.0 (OK)
qdarkstyle >=2.6.4 :  2.6.8 (OK)
sphinx >=0.6.6     :  2.0.1 (OK)
psutil >=0.3       :  5.6.2 (OK)
pyls >=0.19.0;<0.25:  0.24.0 (OK)
nbconvert >=4.0    :  5.5.0 (OK)
pandas >=0.13.1    :  None (NOK)
numpy >=1.7        :  None (NOK)
sympy >=0.7.3      :  None (NOK)
cython >=0.21      :  None (NOK)
qtconsole >=4.2.0  :  4.4.4 (OK)
IPython >=4.0      :  7.5.0 (OK)
matplotlib >=2.0.0 :  None (NOK)
pylint >=0.25      :  2.3.1 (OK)
PyLS Code Completion Bug

Most helpful comment

Thanks a lot for the video! I was able to reproduce the error and now I know how to solve it.

All 10 comments

Also, I am using Spyder Beta using pip on my Ubuntu machine (not conda), just in case it helps. Please do let me know if there is any other details I can provide.

I have code that uses Argparse (which I am practicing)

Please post a simple code that generates this error. Without that we can't help you.

Hi @ccordoba12 , sorry about the delayed response. I don't think this is due to specific code in question, as other people seem to be having similar behavior with different code. However, here is the code snippet I used. I have changed the content of the strings.

import argparse

if __name__=='__main__':
    parser = argparse.ArgumentParser()

    # Parser Characteristics
    parser.description = "generic description"
    parser.epilog = "more details"
    parser.prog = "project_name"

    # Parser Arguments

    parser.add_argument("x", 
                        type=int, 
                        help="the base")
    parser.add_argument("y", 
                        type=int, 
                        help="the exponent")

    # Let's try out groups


    # Create parser instance
    args = parser.parse_args()

    answer = args.x ** args.y

I click on "answer" above and the error occurs. Hope this helps.

Do let me know if you need any other details. Thank you for helping with the development of Spyder - the beta looks so awesome!!!

I click on "args" above and the error occurs

What do you mean by this? You just did a simple mouse click or a Ctrl+click?

Thank you for helping with the development of Spyder - the beta looks so awesome!!!

Thanks for your kind words!

I did a simple mouse (left) click on the variable "args" (and not a Ctrl+click) - I think this is the very first time something is clicked within the editor window after Spyder is started.

So when does this happen exactly? You just open Spyder, make a mouse click on any file and the error is triggered?

I made a small screen video recording of exactly what happens, I hope this helps.

Video: https://drive.google.com/file/d/1sKX2tp92BxRdFv-QnDVnc1j8Fk2XdI_F/view

Please let me know it is not playing for any reason.

Thanks a lot for the video! I was able to reproduce the error and now I know how to solve it.

Thank you! :) :+1: Happy I could help!

Please run

pip install jedi==0.14.1 python-language-server==0.28.1

to fix this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabrielclow picture gabrielclow  路  3Comments

hedeqing picture hedeqing  路  3Comments

JesterEE picture JesterEE  路  3Comments

dalthviz picture dalthviz  路  3Comments

yogu220172 picture yogu220172  路  3Comments