1

Current python#complete doesn't support any python script with the following import statement:

from . import module
from .modulea import abc

It will show "from: syntax error..." in vim.

Anyone has any clue to solve it?

I spend some time today just to resolve this issue myself by going through the pythoncomplete script. I was able to solve it through some hack on the _parsedotname function. I am not sure how portable is my hacking due to the issue on convert the '.' into absolute path but it works in my machine. Below are my changes(yeah, you see lots of print statement which I use it to understand the code flow...)

def _parsedotname(self,pre=None):
    #returns (dottedname, nexttoken)
    name = []
    absolute_relative_path = False
    if pre is None:
        tokentype, token, indent = self.next()
        #print tokentype, token, indent
        if tokentype == 51 and token == '.':
            import os
            import sys
            #print os.path.abspath(os.curdir)
            fullpath = os.path.abspath(os.curdir)
            paths = fullpath.split(os.path.sep) 
            n_ = -1
            #print fullpath
            pyexeindex = sys.path.index(os.path.dirname(sys.executable))
            #print sys.path[pyexeindex:]
            while fullpath not in sys.path[pyexeindex:]:
                fullpath = os.path.sep.join(paths[:n_])
                #print fullpath
                n_ -= 1
            if fullpath == '':
                return ('', token)
            absolute_relative_path = True
            name = '.'.join(paths[n_+1:])
            #print name
        elif tokentype != NAME and token != '*':
            #print 'should not here'
            return ('', token)
    else: token = pre
    if '.' in name:
        name = name.split('.')
    else:
        name.append(token)

    while True:
        if not absolute_relative_path:
            tokentype, token, indent = self.next()
            if token != '.': break
        tokentype, token, indent = self.next()
        if not absolute_relative_path:
            if tokentype != NAME: break
        else:
            absolute_relative_path = False
            if tokentype == NAME and token == 'import':
                return (".".join(name), token)
        name.append(token)
    return (".".join(name), token)

Now, it worked for both:

from . import module
from .moduleA import moduleB
sgwong513
  • 275
  • 1
  • 8

1 Answers1

1

I suppose you're using the vim internal pythoncomplete.

As I wrote here: Python docstring with vim pythoncomplete is not displaying newlines for my own class functions

pythoncomplete is a pretty simple tool, that does most of its completions by executing the import statements (Which is pretty dangerous by the way). Solving it is probably not the best idea, because I'm currently trying to do that (writing a good python auto-completion).

But I don't think my version will be ready to do what you want in another one or two months, but it's already really far, I will tell you when I'm ready.

Community
  • 1
  • 1
Dave Halter
  • 15,556
  • 13
  • 76
  • 103
  • Is it [here](https://github.com/davidhalter/jedi)? And another question: you will post it to vim.org when finished (as a maintainer of VAM-kr I won’t miss this event)? – ZyX May 07 '12 at 19:21
  • Yes it's there, I will tell you here and most probably post to vim.org, If you really want an auto-completion, which is better than the old one, you can already try it. But it will be much better in the end and I won't be too supportive, yet. – Dave Halter May 07 '12 at 19:27
  • And can I hear the comparison of proposed features between your auto-completion and [Python-mode-klen](https://github.com/klen/python-mode)? I am now using it, completion is much better then shipped with vim. Requires rope. – ZyX May 07 '12 at 19:55
  • Oh, thank you! Didn't see that (Of course I know rope, but it never worked for me). I hope I can look into it. – Dave Halter May 07 '12 at 21:00
  • I am using the vim internal pythoncomplete. It works for simple python completion and for complex code it doesn't work so well. I read its src, its complex for me and haven't really dig out how it work. I wanted to see anyone had solve this issue. It is really good that you are working on a new pythoncomplete, I am really looking forward for your python completion. I might try to use yours and also Python-mode-klen to see how it worked out. Yeah, I also haven't made rope work well in my system.... – sgwong513 May 08 '12 at 02:33
  • @sgwong513 It is not the only completion script using rope, I saw at least two other which means using rope for completion is easy. It does not like unicode in my docstrings very much though. – ZyX May 08 '12 at 09:07
  • Since I had figure out some workaround myself and there is no more appropriate answer, I will just mark this as my solution.... – sgwong513 May 10 '12 at 09:51
  • I'm testing my auto-completion now: https://github.com/davidhalter/jedi I need a few persons, to test and give me feedback. – Dave Halter Sep 06 '12 at 12:57