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