Search code examples
python-3.xpython-multiprocessingpython-jedi

Incorrect jedi completitions for multiprocessing module in python3


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?


Solution

  • 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.