user48956
user48956

Reputation: 15788

Possible to convince Jedi to autocomplete lists?

I'm getting a huge amount of utility out of exposing an object to tree at the command line to a python program. For example:

myprog.py  obj1.obj2.method

Let me execute obj1.obj2.method(), and

myprog.py  obj1.<TAB>
myprog.py  obj1.obj2<TAB>

lets me see what available. Awesome! However, I can't convince jedi to return autocomplete results lists (or dictionaries). I was hoping something hacky this this might work for short lists:

class X:
    pass

x = X()
x2 = X()
x2.y = 456
x.z = [x2]

# Want to get x.z[0].y in the results
prefix = "x.z[0]."

import jedi
# Tell jedi about list elements?
script = jedi.Interpreter(prefix, [{"x.z[0].z": x.z[0].z}])

for c in script.completions():
    print c
sys.exit()

Upvotes: 1

Views: 189

Answers (1)

Dave Halter
Dave Halter

Reputation: 16325

If anything, this should work:

>>> script = jedi.Interpreter(prefix, [{"x": x}])
>>> script.completions()

However at the moment it returns an empty list. I think it would be worth adding an issue to the Jedi issue tracker, since this is something that can definitely be done.

If I remember the Jedi code correctly, Jedi tries to not call getattr in certain cases (like class lookup), but this could easily be changed, since it's:

  1. Not consistent anyway, Jedi would call getattr on objects that are not complicated, like x.y.
  2. The standard library autocompletion also calls getattr.

If you want that, just add an issue to the Jedi issue tracker.

Upvotes: 2

Related Questions