Skip to content

Error when running python-lsp-server with Electron+monaco editor: ERROR pylsp_jsonrpc.endpoint - Failed to handle request #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pplonski opened this issue Nov 23, 2021 · 8 comments

Comments

@pplonski
Copy link

I'm working on an example of the Electron app with monaco-editor and full Python completion. I'm using python-lsp-server. My repo is available at: https://github.com/pplonski/electron-monaco-python-lsp

I'm getting the following error in pylsp:

JSON Server: 2021-11-23 09:45:09,904 CET - ERROR - pylsp_jsonrpc.endpoint - Failed to handle request 42
Traceback (most recent call last):
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 311, in resolve_label
    sig = completion.get_signatures()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/api/classes.py", line 582, in get_signatures
    for s in self._get_signatures()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/api/classes.py", line 570, in _get_signatures
    names = convert_names([self._name], prefer_stubs=True)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/gradual/conversion.py", line 152, in convert_names
    return _python_to_stub_names(names, fallback_to_python=prefer_stubs)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/utils.py", line 16, in wrapper
    return list(func(*args, **kwargs))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/gradual/conversion.py", line 126, in _python_to_stub_names
    for x in _python_to_stub_names([n], fallback_to_python=fallback_to_python):
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/utils.py", line 16, in wrapper
    return list(func(*args, **kwargs))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/gradual/conversion.py", line 132, in _python_to_stub_names
    v = name.get_defining_qualified_value()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/names.py", line 251, in get_defining_qualified_value
    if context.is_module() or context.is_class():
AttributeError: 'NoneType' object has no attribute 'is_module'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp_jsonrpc/endpoint.py", line 116, in consume
    self._handle_request(message['id'], message['method'], message.get('params'))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp_jsonrpc/endpoint.py", line 185, in _handle_request
    handler_result = handler(params)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler
    return method(**(params or {}))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/python_lsp.py", line 350, in m_text_document__completion
    return self.completions(textDocument['uri'], position)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/python_lsp.py", line 261, in completions
    completions = self._hook('pylsp_completions', doc_uri, position=position)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/python_lsp.py", line 156, in _hook
    return hook_handlers(config=self.config, workspace=workspace, document=doc, **kwargs)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 327, in traced_hookexec
    return outcome.get_result()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_result.py", line 33, in from_call
    result = func()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 324, in <lambda>
    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 68, in pylsp_completions
    ready_completions = [
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 69, in <listcomp>
    _format_completion(
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 180, in _format_completion
    'label': _label(d, resolve_label),
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 226, in _label
    sig = LABEL_RESOLVER.get_or_create(definition)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 296, in get_or_create
    self._cache[key] = self.resolve_label(completion)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 314, in resolve_label
    log.warning(
  File "/usr/lib/python3.8/logging/__init__.py", line 1458, in warning
    self._log(WARNING, msg, args, **kwargs)
TypeError: _log() got an unexpected keyword argument 'completion'

Reproduce steps

  1. Install:
pip install python-lsp-server
pip install python-lsp-server[yapf]
pip install numpy
  1. Run electron app and write:
import numpy
numpy.random.

After the last dot the exception will be thrown.

In the Electron app I get:

Error
TypeError: _log() got an unexpected keyword argument 'completion'

Error: TypeError: _log() got an unexpected keyword argument 'completion'
at handleResponse (http://localhost:1212/renderer.dev.js:240484:48)
at processMessageQueue (http://localhost:1212/renderer.dev.js:240299:17)
at http://localhost:1212/renderer.dev.js:240283:13

Is this issue related to python-lsp-server or rather to my settings and client code in Electron?

@rcjsuen
Copy link

rcjsuen commented Nov 23, 2021

  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 226, in _label
    sig = LABEL_RESOLVER.get_or_create(definition)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 296, in get_or_create
    self._cache[key] = self.resolve_label(completion)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 314, in resolve_label
    log.warning(

@pplonski I installed pylsp but my jedi_completion.py only has 231 lines. I don't know why you are in line 314. 🤔

@pplonski
Copy link
Author

That's my pip freeze on fresh venv

jedi==0.18.1
numpy==1.21.4
parso==0.8.2
pluggy==1.0.0
python-lsp-jsonrpc==1.0.0
python-lsp-server==1.2.4
ujson==4.3.0
yapf==0.31.0

@rcjsuen
Copy link

rcjsuen commented Nov 23, 2021

@pplonski Perhaps you can update to a newer version. This is what I have.

jedi==0.18.1
parso==0.8.2
pluggy==1.0.0
python-lsp-jsonrpc==1.0.0
python-lsp-server==1.3.1
ujson==4.3.0

From the error message it is clear there was a bug in 1.2.4.

>>> import logging
>>> log = logging.getLogger(__name__)
>>> completion = "abc"
>>> e = "def"
>>> log.warning('Something went wrong when resolving label for {completion}: {e}', completion=completion, e=e)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1458, in warning
    self._log(WARNING, msg, args, **kwargs)
TypeError: _log() got an unexpected keyword argument 'completion'

@pplonski
Copy link
Author

I've updated python-lsp-server, my pip freeze:

jedi==0.18.1
numpy==1.21.4
parso==0.8.2
pluggy==1.0.0
python-lsp-jsonrpc==1.0.0
python-lsp-server==1.3.1
ujson==4.3.0
yapf==0.31.0

the error traceback that I got:

JSON Server: 2021-11-24 09:04:30,010 CET - ERROR - pylsp_jsonrpc.endpoint - Failed to handle request 39
Traceback (most recent call last):
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/_resolvers.py", line 81, in resolve
    sig = completion.get_signatures()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/api/classes.py", line 582, in get_signatures
    for s in self._get_signatures()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/api/classes.py", line 570, in _get_signatures
    names = convert_names([self._name], prefer_stubs=True)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/gradual/conversion.py", line 152, in convert_names
    return _python_to_stub_names(names, fallback_to_python=prefer_stubs)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/utils.py", line 16, in wrapper
    return list(func(*args, **kwargs))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/gradual/conversion.py", line 126, in _python_to_stub_names
    for x in _python_to_stub_names([n], fallback_to_python=fallback_to_python):
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/utils.py", line 16, in wrapper
    return list(func(*args, **kwargs))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/gradual/conversion.py", line 132, in _python_to_stub_names
    v = name.get_defining_qualified_value()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/jedi/inference/names.py", line 251, in get_defining_qualified_value
    if context.is_module() or context.is_class():
AttributeError: 'NoneType' object has no attribute 'is_module'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp_jsonrpc/endpoint.py", line 116, in consume
    self._handle_request(message['id'], message['method'], message.get('params'))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp_jsonrpc/endpoint.py", line 185, in _handle_request
    handler_result = handler(params)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler
    return method(**(params or {}))
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/python_lsp.py", line 350, in m_text_document__completion
    return self.completions(textDocument['uri'], position)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/python_lsp.py", line 261, in completions
    completions = self._hook('pylsp_completions', doc_uri, position=position)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/python_lsp.py", line 156, in _hook
    return hook_handlers(config=self.config, workspace=workspace, document=doc, **kwargs)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 327, in traced_hookexec
    return outcome.get_result()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_result.py", line 33, in from_call
    result = func()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 324, in <lambda>
    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 67, in pylsp_completions
    ready_completions = [
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 68, in <listcomp>
    _format_completion(
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 179, in _format_completion
    'label': _label(d, resolve_label_or_snippet),
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/jedi_completion.py", line 204, in _label
    sig = LABEL_RESOLVER.get_or_create(definition)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/_resolvers.py", line 66, in get_or_create
    self._cache[key] = self.resolve(completion)
  File "/home/piotr/sandbox/example/pyls/venv/lib/python3.8/site-packages/pylsp/plugins/_resolvers.py", line 84, in resolve
    log.warning(
  File "/usr/lib/python3.8/logging/__init__.py", line 1458, in warning
    self._log(WARNING, msg, args, **kwargs)
TypeError: _log() got an unexpected keyword argument 'completion'

@pplonski
Copy link
Author

I've solved the issue by downgrading jedi:

pip install jedi==0.17.2

Maybe it is somehow connected with davidhalter/jedi#1714 Don't know.

Thank you @rcjsuen for the help!

@ccordoba12
Copy link
Member

This turned out to be an error in our side. See issue #121 and PR #122.

@rcjsuen
Copy link

rcjsuen commented Nov 25, 2021

This turned out to be an error in our side. See issue #121 and PR #122.

Yay to f-strings! Thanks for fixing this, @ccordoba12.

@ccordoba12
Copy link
Member

The fix is now part of our 1.3.2 version (just released).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants