vheon / JediHTTP

Simple http wrapper around jedi
Apache License 2.0
40 stars 9 forks source link

RecursionError while completing pymongo objects #46

Closed zhaojames0707 closed 6 years ago

zhaojames0707 commented 6 years ago

description

I use Vim with YCM, and they worked very well most of the time, but it seems that something is wrong completing pymongo objects.

Relevant piece of code:

import pymongo
pymongo.MongoClient().[cursor-here]

After I inputed the dot after pymongo.MongoClient(), nothing shows up. I looked at the log file of YCM, and it shows:

2017-12-27 23:24:27,851 - INFO - Starting new HTTP connection (1): 127.0.0.1
2017-12-27 23:24:28,609 - ERROR - Exception from semantic completer (using general): Traceback (most recent call last):
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 103, in GetCompletions
    .ComputeCandidates( request_data ) )
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 218, in ComputeCandidates
    candidates = self._GetCandidatesFromSubclass( request_data )
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 231, in _GetCandidatesFromSubclass
    raw_completions = self.ComputeCandidatesInner( request_data )
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/python/jedi_completer.py", line 272, in ComputeCandidatesInner
    for completion in self._JediCompletions( request_data ) ]
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/python/jedi_completer.py", line 277, in _JediCompletions
    request_data )[ 'completions' ]
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/python/jedi_completer.py", line 215, in _GetResponse
    response.raise_for_status()
  File "/Users/zhaoxiaoyu/k-vim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/models.py", line 840, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http://127.0.0.1:58047/completions

I manually started JediHTTP server:

python jedihttp/__main__.py  --port=39621 --host=0.0.0.0

And call it with curl command:

curl -X POST \
  http://127.0.0.1:39621/completions \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: d2722db6-77a4-14bb-874f-57300fc70471' \
  -H 'content-type: application/json' \
  -d '{
    "col": 22,
    "line": 2,
    "source": "import pymongo\npymongo.MongoClient().",
    "source_path": "test.py"
}'

RecursionError shows in the server console output:

  File "/root/JediHTTP/vendor/jedi/jedi/evaluate/cache.py", line 40, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/root/JediHTTP/vendor/jedi/jedi/evaluate/context/function.py", line 226, in get_params
    return self.var_args.get_params(self)
  File "/root/JediHTTP/vendor/jedi/jedi/evaluate/arguments.py", line 70, in get_params
    return get_params(execution_context, self)
  File "/root/JediHTTP/vendor/jedi/jedi/evaluate/param.py", line 51, in get_params
    param_dict[param.name.value] = param
  File "/root/JediHTTP/vendor/parso/parso/python/tree.py", line 1104, in name
    if self._tfpdef().type == 'tfpdef':
  File "/root/JediHTTP/vendor/parso/parso/python/tree.py", line 1096, in _tfpdef
    offset = int(self.children[0] in ('*', '**'))
RecursionError: maximum recursion depth exceeded while calling a Python object

My environment: JediHTTP: latest commit of master branch, commit id is: d283a73f26cdf36069ef99353a072184f794e4d7 OS: macOS 10.13.2 Python: 3.5.1

I can also reproduce the issue on:

OS: Debian 8 python: 3.6.4

Hope the info above may help, thx!

zhaojames0707 commented 6 years ago

I forgot to mention that the version of pymongo is 3.6.0.

puremourning commented 6 years ago

I suspect this is hitting a limitation of Jedi. Is it possible to reproduce with raw Jedi? JediHTTP is really just wrapping the Jedi API.

micbou commented 6 years ago

Took me some time but I was able to reduce the problem to the following code:

import jedi
jedi.Script("dict().values().").completions()

I reported the issue to the Jedi repository: https://github.com/davidhalter/jedi/issues/1014.

micbou commented 6 years ago

Fixed by PR https://github.com/Valloric/ycmd/pull/1028.