Currently I am writing all my Python code using Neovim and a couple of plugins to provide auto-completion, linting, etc.

For code auto-completion, I use deoplete as the completion and engine and deoplete-jedi as the completion source for Python. They work great most of the time. But, sometimes I can not get auto-completion for some object instance. For example, auto-completion for object instances returned by the in the Pillow does not work. I decide to take a look.

At first, I think it is an issue of deoplete or deoplete-jedi. But I find that the Image instances return other methods, e.g.,, work as expected. If it is an issue of deoplete or deoplete-jedi, then auto-completion should not work anymore. Maybe it is due to the static type checker Jedi that deoplete-jedi relies on?

To find out the reason, I use the following script to check if Jedi can provide completion for the Image instances returned from and method1:

import jedi

source1 = '''
from PIL import Image
im ='test.jpg', (128, 128))

script1 = jedi.Script(source1, 4, len('im.'), '')

source2 = '''
from PIL import Image
im ='test.jpg')
script2 = jedi.Script(source2, 4, len('im.'), '')

As expected, the first print() shows a list of completion results while the second print() shows an empty list.

So this is indeed an issue of Jedi. I filed an issue on the Jedi GitHub repo. After a while, I got an reply from the author of this project. The reason is that Jedi can infer the type returned by method since it is too dynamic to infer. The author suggested that I may use type hints to help Jedi infer the type of the return objects. I tried two ways based on the type hinting documentation of Jedi.

The first method is to use function annotations. I find the source file of in my system and change the following definition

def open(fp, mode="r") :


def open(fp, mode="r") -> Image:

Now the auto-completion works for instance returned by method.

The second method is to use type hints in inline comment. But the auto-completion does not work anymore. My test script is:

import jedi

source = '''
from PIL import Image
im ='test.png')  # type: Image

script = jedi.Script(source, 4, len('im.'), '')

The print function shows an empty list.

So for now, you may stick to function annotations if you want type hints to work for Jedi.


  1. The script is adapted from the tutorial code of Jedi from here