Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting six and six.moves modules to autocomplete in pycharm

Is it possible to get imports for the six module to work in PyCharm? I realize the module does some playing with imports that confuses PyCharm but I was hoping there was some type of workaround.

For example, I'd like the following to work properly in PyCharm or IntelliJ::

from six.moves import BaseHTTPServer
like image 268
kylehyde215 Avatar asked Mar 25 '16 04:03

kylehyde215


People also ask

How do you autocomplete in PyCharm?

Press Ctrl+Space or choose Code | Code Completion | Basic from the main menu. If necessary, press Ctrl+Space for the second time (or press Ctrl+Alt+Space ).

How do I turn off auto complete in PyCharm?

Go to File > Settings (or Ctrl + Alt + S ) > [IDE Settings] > Editor > Code Completion. The "Autopopup code completion" setting will determine if the popup opens automatically. Below it, the "Insert selected variant by typing dot, space, etc." is likely the setting you want to turn off.


1 Answers

The imports are dynamic so pycharm can't do any static analysis of the code to determine the type information.

Pycharm gets around this for languages like javascript by using static type definition files (Settings -> Languages & Frameworks -> Javascript -> Libraries).

This is the python equivalent: https://www.jetbrains.com/help/pycharm/2016.2/using-python-skeletons.html - a parallel set of python files with static exports allowing static analysis.

At the present time the skeleton definitions seem to really be a proof of concept as they are very sparse (there is no six, and while a django module exists it is almost empty -- there is no django.utils.six.moves that you could just copy over). You could manually add all the six.moves exports but this would be a non-trivial effort.

If you did want to try modifying the skeleton files, on OSX:

cd ~/Library/Preferences/PyCharm2016.2 git clone https://github.com/JetBrains/python-skeletons.git and modify files in there (although I was never actually able to get it to detect my changes)

like image 53
Levi Avatar answered Sep 21 '22 17:09

Levi