2

I would like to improve the auto-completion in a python console that is part of a project I am working on. While jedi works great for this in general, there is one special case where it fails to find any completion suggestions: Properties of classes defined as methods with the @property decorator. The following example should explain my problem:

import jedi

class B:
    def __init(self):
        pass

    def see_me(self):
        pass

class A:
    def __init__(self):
        pass

    @property
    def b(self):
        return B()

    def get_b(self):
        return B()

a = A()

script = jedi.Interpreter('a.b.', [locals()])
comps = script.completions()
print('Interpreter completion (property): ', comps)

script = jedi.Interpreter('a.get_b().', [locals()])
comps = script.completions()
print('Interpreter completion (method): ', comps)

executing the script returns:

Interpreter completion (property):  []
Interpreter completion (method):  [<Completion: see_me>, ...]

When the method with the @property decorator is called, no completion is found by jedi. The "normal" method works just fine. Am I using jedi the wrong way here or is this just one of the cases that is too hard to solve for jedi?

Thanks in advance for your help!

PS: I also tried putting the whole code until a = A() into a string and used Script instead of Interpreter to get the completion. Interestingly this was then successful in finding the correct completion also for the @propertydecorated method.

Brow 71189
  • 21
  • 2
  • You're on to something here. Please add an issue in Jedi's issue tracker. I wouldn't say this is a bug, but it's clearly something where Jedi could perform better. – Dave Halter Dec 02 '18 at 18:33
  • Sure I will add it. Do you know why it works when using "Script" instead of "Interpreter". I tried looking through the source code to find a reason for that (and maybe a simple fix) but couldn't figure it out. – Brow 71189 Dec 04 '18 at 04:01
  • In one case you're giving Jedi actual Python object in the other you give Jedi code (a string). One is basically static analysis, while the other is not, it actually accesses the given Python objects. It's hard to get all information out of Python objects. – Dave Halter Dec 12 '18 at 15:53

0 Answers0