Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annoying sublime text autocompletion for Python after period (`self` keyword)

I'm using sublime text 3 for python development. I have autocompletion turned on as I type, which works. I expect, that when I type an object name followed by a period, a list of object's methods/attributes would popup. It does not happen, so I press Tab.

import time
time.[TAB]

What happens now, is just absolutely weird! . is replaced by self., so I end up with

import time
timeself.

I was looking in all setting files, I tried packages python completions, code intel and code complice, but none of them disabled this "feature", which drives me crazy!

Finally, I have found Jedi package, which solved this issue for the text editor. But I still have problems in the interpreter window (package SublimeREPL). By the way, if I install both Jedi and code complice, the autocompletion in the REPL seems to work better, but it offers some irrelevant crap like %%! or %%HTML. And yes, if I press [TAB] twice, I still end up with timeself. instead of time.!

Does anyone know what's going on? Where this . -> self. behavior is coming from? How to disable %%! stuff?

like image 354
R Kiselev Avatar asked Dec 24 '22 06:12

R Kiselev


2 Answers

I had this problem myself, and it was not easy to track down.

The problem is not caused by any package. I found out after running default built of Sublime text 3. While I highly recommend Anaconda (as mentioned by MattDMo), the problem can occur also when Anaconda is installed.

The problem:

The cause of the problem is the default Python snippet shipped with Sublime Text 3 called self.sublime-snippet and looks like this:

<snippet>
    <content><![CDATA[self.]]></content>
    <tabTrigger>.</tabTrigger>
    <scope>source.python</scope>
    <description>self</description>
</snippet>

In Sublime text 2, this file can simply be removed, but the default snippets in ST3 isn't stored in the same way, so there is no way to easily delete this file.

The solution:

This stack overflow answer explains how to extract the package information for a language, in this case Python. The snippet can then be deleted as normally.

Update:

The snippet has now been removed in the source code due to this problem. Probably included in next update. Source: https://github.com/sublimehq/Packages/issues/473

like image 166
Martin Hallén Avatar answered Dec 26 '22 20:12

Martin Hallén


I would highly recommend getting rid of your other completion packages and install Anaconda (no relation to the Anaconda Python distribution). I've been using it for a couple of years now, and I absolutely love it. Basically all you need to do to set it up is provide a path for "python_interpreter" in Anaconda's settings or in your project's settings, and it just works. No taking forever to index everything like SublimeCodeIntel, and no need to set up a separate linter if you don't want to, because several linters are built-in. Virtualenvs are seamless. Anaconda will see all the modules available to the version of Python specified by "python_interpreter", so you don't need to worry about adding extra paths to the environment through settings. Make sure you copy all of the default settings file into the user settings file, then change the options as needed. Project-specific settings override user settings, so you can customize even more by editing your project.

BTW, I'm not affiliated with the project in any way, except for a minor pull request or two, I'm just a very satisfied user.

like image 31
MattDMo Avatar answered Dec 26 '22 18:12

MattDMo