1
0
forked from VimPlug/jedi

Implement Import.is_nested method.

This commit is contained in:
Dave Halter
2014-12-11 16:17:07 +01:00
parent 6406bfb3c2
commit 6818d3affa
4 changed files with 35 additions and 28 deletions

View File

@@ -992,16 +992,7 @@ class Import(Simple):
raise ValueError('Name should be defined in the import itself')
def is_nested(self):
"""
This checks for the special case of nested imports, without aliases and
from statement::
import foo.bar
"""
return False
# TODO use this check differently?
return not self.alias and not self.from_names \
and len(self.namespace_names) > 1
return False # By default, sub classes may overwrite this behavior
def is_star_import(self):
return self.children[-1] == '*'
@@ -1102,6 +1093,16 @@ class ImportName(Import):
# dotted_names
yield as_name.children[::2], alias
def is_nested(self):
"""
This checks for the special case of nested imports, without aliases and
from statement::
import foo.bar
"""
return [1 for path, alias in self._dotted_as_names()
if alias is None and len(path) > 1]
def aliases(self):
return dict((alias, path[-1]) for path, alias in self._dotted_as_names()
if alias is not None)