Esempio n. 1
0
def LAZY_IMPORT(self, node):
    from breezy.lazy_import import ImportProcessor
    processor = ImportProcessor()
    if not isinstance(node.args[1], ast.Str):
        # Not sure how to deal with this..
        return
    import_text = node.args[1].s
    scope = {}
    processor.lazy_import(scope, import_text)
    for name, (path, sub, scope) in processor.imports.items():
        importation = ImportationFrom(name, node, '.'.join(path), scope)
        self.addBinding(node, importation)
Esempio n. 2
0
 def test_importfrom_submodule_member_as(self):
     binding = ImportationFrom('d', None, 'a.b', 'c')
     assert binding.source_statement == 'from a.b import c as d'
     assert str(binding) == 'a.b.c as d'
Esempio n. 3
0
 def test_importfrom_member_as(self):
     binding = ImportationFrom('c', None, 'a', 'b')
     assert binding.source_statement == 'from a import b as c'
     assert str(binding) == 'a.b as c'
Esempio n. 4
0
 def test_importfrom_relative_with_module_as(self):
     binding = ImportationFrom('c', None, '..a', 'b')
     assert binding.source_statement == 'from ..a import b as c'
     assert str(binding) == '..a.b as c'
Esempio n. 5
0
 def test_importfrom_relative_parent(self):
     binding = ImportationFrom('a', None, '..', 'a')
     assert binding.source_statement == 'from .. import a'
     assert str(binding) == '..a'
Esempio n. 6
0
 def test_importfrom_submodule_member_as(self):
     binding = ImportationFrom("d", None, "a.b", "c")
     assert binding.source_statement == "from a.b import c as d"
     assert str(binding) == "a.b.c as d"
Esempio n. 7
0
 def test_importfrom_member_as(self):
     binding = ImportationFrom("c", None, "a", "b")
     assert binding.source_statement == "from a import b as c"
     assert str(binding) == "a.b as c"
Esempio n. 8
0
 def test_importfrom_relative_with_module_as(self):
     binding = ImportationFrom("c", None, "..a", "b")
     assert binding.source_statement == "from ..a import b as c"
     assert str(binding) == "..a.b as c"
Esempio n. 9
0
 def test_importfrom_relative_parent(self):
     binding = ImportationFrom("a", None, "..", "a")
     assert binding.source_statement == "from .. import a"
     assert str(binding) == "..a"