vheon / JediHTTP

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

Crash on autocompleting PyQt5.QtWidgets #52

Closed atfoc closed 6 years ago

atfoc commented 6 years ago

Here is my python code:

import PyQt5.QtWidgets
PyQt5.QtWidgets.

now when I try to trigger autocomplite nothing happens. So I decided to check jediHttp logs and this is what I found:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/cache.py", line 46, in wrapper
    return getattr(self, name)
AttributeError: 'CompiledName' object has no attribute '_infer'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 555, in wrapper
    return cache[key][0]
KeyError: (140100081884040, 140099280898536)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 156, in memoizer
    result = cache[key]
KeyError: (<function _get_faked at 0x7f6b97b36158>, (None, <PyQt5.QtWidgets.QApplication object at 0x7f6b979d1b88>, None), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/bottle/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/bottle/bottle.py", line 1732, in wrapper
    rv = callback(*a, **ka)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/hmac_plugin.py", line 58, in wrapper
    body = callback( *args, **kwargs )
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 84, in completions
    response = _FormatCompletions( script.completions() )
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 153, in _FormatCompletions
    } for completion in completions ]
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 153, in <listcomp>
    } for completion in completions ]
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/api/classes.py", line 148, in type
    return self._name.api_type
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 275, in api_type
    return next(iter(self.infer())).api_type
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/cache.py", line 48, in wrapper
    result = func(self)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 280, in infer
    return [_create_from_name(self._evaluator, module, self.parent_context, self.string_name)]
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 515, in _create_from_name
    return create(evaluator, obj, parent_context=compiled_object, faked=faked)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 558, in wrapper
    result = func(evaluator, obj, parent_context, module, faked)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 582, in create
    faked = fake.get_faked(evaluator, module, obj, parent_context=parent_context)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 199, in get_faked
    faked, fake_module = _get_faked(module and module.obj, obj, name)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 160, in memoizer
    result = obj(*args, **kwargs)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 171, in _get_faked
    result, fake_module = _faked(module, obj, name)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 110, in _faked
    module = get_module(obj)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 86, in get_module
    obj = obj.__objclass__
RuntimeError: wrapped C/C++ object of type QApplication has been deleted
Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/cache.py", line 46, in wrapper
    return getattr(self, name)
AttributeError: 'CompiledName' object has no attribute '_infer'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 555, in wrapper
    return cache[key][0]
KeyError: (140100081884040, 140099280655584)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 156, in memoizer
    result = cache[key]
KeyError: (<function _get_faked at 0x7f6b97b36158>, (None, <PyQt5.QtWidgets.QApplication object at 0x7f6b979d1b88>, None), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/bottle/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/bottle/bottle.py", line 1732, in wrapper
    rv = callback(*a, **ka)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/hmac_plugin.py", line 58, in wrapper
    body = callback( *args, **kwargs )
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 84, in completions
    response = _FormatCompletions( script.completions() )
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 153, in _FormatCompletions
    } for completion in completions ]
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp/handlers.py", line 153, in <listcomp>
    } for completion in completions ]
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/api/classes.py", line 148, in type
    return self._name.api_type
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 275, in api_type
    return next(iter(self.infer())).api_type
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/cache.py", line 48, in wrapper
    result = func(self)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 280, in infer
    return [_create_from_name(self._evaluator, module, self.parent_context, self.string_name)]
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 515, in _create_from_name
    return create(evaluator, obj, parent_context=compiled_object, faked=faked)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 558, in wrapper
    result = func(evaluator, obj, parent_context, module, faked)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/__init__.py", line 582, in create
    faked = fake.get_faked(evaluator, module, obj, parent_context=parent_context)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 199, in get_faked
    faked, fake_module = _get_faked(module and module.obj, obj, name)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 160, in memoizer
    result = obj(*args, **kwargs)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 171, in _get_faked
    result, fake_module = _faked(module, obj, name)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 110, in _faked
    module = get_module(obj)
  File "/home/atfoc/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/compiled/fake.py", line 86, in get_module
    obj = obj.__objclass__
RuntimeError: wrapped C/C++ object of type QApplication has been deleted

So I was wondering is this something easy to fix Thanks in an advance

atfoc commented 6 years ago

I think I found the problem. It wasn't a problem with jediHttp but something with jedi and pyqt module. All I did was capture exception in function _FormatCompletions and this way it works, or at least I think so I don't know why exceptions where happening but this made autocomplite work

I changed _FormatCompletions to this

def _FormatCompletions( completions ):
  #return {
  #    'completions': [ {
  #        'module_path': completion.module_path,
  #        'name':        completion.name,
  #        'type':        completion.type,
  #        'line':        completion.line,
  #        'column':      completion.column,
  #        'docstring':   completion.docstring(),
  #        'description': completion.description,
  #    } for completion in completions ]
  #}
  res = {}
  arr = []
  for completion in completions:
    try:
      arr.append({
              'module_path': completion.module_path,
              'name':        completion.name,
              'type':        completion.type,
              'line':        completion.line,
              'column':      completion.column,
              'docstring':   completion.docstring(),
              'description': completion.description,
            })
    except Exception:
      continue
  res["completions"] = arr
  return res

I hope this is ok :)

micbou commented 6 years ago

This is fixed in the latest version of Jedi, which is going to be released soon. Note that we are probably going to drop JediHTTP and use directly Jedi in ycmd with that release.