Search code examples
pythonautocompletesublimetext3sublimerepl

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?


Solution

  • 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