0

Working with atom's autocomplete-python which uses jedi I've found that there are incorrect suggestions for multiprocessing module in python3. Here is an example:

>>> import jedi
>>> source = '''
... import multiprocessing as mp
... mp.Pro'''
>>> script = jedi.Script(source, 3, len('mp.Pro'), 'example.py')
>>> script.completions()
[<Completion: process>]

Module actually has process package but also it has Process class inside of module scope:

>>> import multiprocessing as mp
>>> [n for n in mp.__all__ if n.endswith('rocess')]
['Process', 'current_process']

Comparing python2's and python3's multiprocessing module I've found that they are slightly different. Modern version imports namespace of the default context's namespace:

globals().update((name, getattr(context._default_context, name))
             for name in context._default_context.__all__)
__all__ = context._default_context.__all__

Unfortunately, I don't have any ideas how to resolve this problem or workaround it. Do you have any suggestions?

frist
  • 1,918
  • 12
  • 25

1 Answers1

1

Jedi doesn't understand writing to globals().

This is explicitly mentioned in http://jedi.readthedocs.io/en/latest/docs/features.html#unsupported-features

For a very long time I haven't even considered implementing this, now I'm open to it. But it might a long time. (It wouldn't be a big performance killer anymore.)

However for now I think you just have to live with this issue.

Dave Halter
  • 15,556
  • 13
  • 76
  • 103
  • Thank you for your answer, I hope you will get it in a while. Also it's interesting for me do you know how does autocomplete work in IDEs like PyCharm? – frist Nov 10 '16 at 07:22
  • 1
    It works in a similar way. However additionally they have a lot of "skeleton" files (I think that's what they are calling them). Type inference for multiprocessing would probably get redirected to such a skeleton file to allow better autocompletion (where there's no `globals()`. Jedi in contrast has mostly tried to understand Python code to the full extent. I feel like now Jedi has come to the point where a plugin and/or skeleton system would be necessary. – Dave Halter Nov 10 '16 at 16:15