jedi Interpreter completion fails for properties

188 Views Asked by At

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.

0

There are 0 best solutions below