davidhalter / jedi

Awesome autocompletion, static analysis and refactoring library for python
http://jedi.readthedocs.io
Other
5.81k stars 508 forks source link

Jedi is throwing error while invoking asyncio module based function #767

Closed ehzawad closed 7 years ago

ehzawad commented 8 years ago
"/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/api/completion.py", line 161, in get_context_completions
completion_names += self._trailer_completions(atom_expr)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/api/completion.py", line 197, in _trailer_completions
scopes = self._evaluator.eval_element(atom_expr)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 262, in eval_element
return self.eval_element_if_evaluated(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init_.py", line 275, in eval_element_if_evaluated
return self.eval_element_cached(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/cache.py", line 41, in wrapper
rv = function(obj, args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 279, in eval_element_cached
return self.eval_element_not_cached(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/debug.py", line 81, in wrapper
return func(args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 286, in eval_element_not_cached
types = self.eval_atom(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 357, in eval_atom
return self.find_types(scope, atom, stmt.start_pos, search_global=True)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init_.py", line 142, in find_types
return f.find(scopes, search_global)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/debug.py", line 81, in wrapper
return func(args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/finder.py", line 97, in find
types = self.names_to_types(names, search_global)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/finder.py", line 286, in names_to_types
new_types = _name_to_types(self._evaluator, name, self.scope)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/cache.py", line 41, in wrapper
rv = function(obj, args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/finder.py", line 334, in _name_to_types
types = _remove_statements(evaluator, typ, name)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/finder.py", line 382, in _remove_statements
types |= evaluator.eval_statement(stmt, seek_name=name)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/debug.py", line 81, in wrapper
return func(args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 158, in eval_statement
types = self.eval_element(rhs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/init.py", line 262, in eval_element
return self.eval_element_if_evaluated(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init_.py", line 275, in eval_element_if_evaluated
return self.eval_element_cached(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/cache.py", line 41, in wrapper
rv = function(obj, args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 279, in eval_element_cached
return self.eval_element_not_cached(element)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/debug.py", line 81, in wrapper
return func(args, *kwargs)
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 299, in eval_element_not_cached
types = self.eval_atom(element.children[0])
File "/home/hell/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/vendor/jedi/jedi/evaluate/__init.py", line 361, in _eval_atom
c = atom.children
AttributeError: 'Keyword' object has no attribute 'children'

import asyncio

async def http_get(domain):
    reader, writer = await asyncio.open_connection(domain, 80)

    writer.write(b'\r\n'.join([
        b'GET / HTTP/1.1',
        b'Host: %b' % domain.encode('latin-1'),
        b'Connection: close',
        b'', b''
    ]))

    async for line in reader:
        print('>>>', line)

    writer.close()
davidhalter commented 8 years ago

Can you retry with the current jedi dev branch?

micbou commented 8 years ago

Here's a reproducible testcase with Jedi be2a97cd36ce1b7d6f587ef122efc3433b1e8ae2:

import jedi

args = (
  '''import asyncio
async def test():
    reader, writer = await asyncio.open_connection()
    writer.
''',
  4,
  len('    writer.'),
  'example.py'
)

jedi.Script(*args).completions()
xuboying commented 8 years ago

Chasing on this issue for #775

ehzawad commented 8 years ago

I swear, concurrency is always hard.. Can we take advantages from new vim 8.0 packages..? Asynchronous I/O support, channels ~

Vim can now exchange messages with other processes in the background. This makes it possible to have servers do work and send back the results to Vim. See |channel-demo| for an example, this shows communicating with a Python server.

Closely related to channels is JSON support. JSON is widely supported and can easily be used for inter-process communication, allowing for writing a server in any language. The functions to use are |json_encode()| and |json_decode()|.

This makes it possible to build very complex plugins, written in any language and running in a separate process.

Jobs ~

Vim can now start a job, communicate with it and stop it. This is very useful to run a process for completion, syntax checking, etc. Channels are used to communicate with the job. Jobs can also read from or write to a buffer or a file. See |job_start()|.

Timers ~

Also asynchronous are timers. They can fire once or repeatedly and invoke a function to do any work. For example: > let tempTimer = timer_start(4000, 'CheckTemp') This will call the CheckTemp() function four seconds (4000 milli seconds) later. See |timer_start()|.

Ref : :help version8

davidhalter commented 8 years ago

@ehzShelter WTF are you talking about. This issue has absolutely nothing to do with either async stuff or VIM. :laughing:

ehzawad commented 8 years ago

No idea.. :D

micbou commented 7 years ago

This is fixed in the dev branch.

ehzawad commented 7 years ago

Thank you :)