Ejemplo n.º 1
0
 def test_from_module_import_star(self):
     self.template([
         ("from apple import *",
          python.ImportFrom("apple", (python.alias("*", None), ), 0)),
         ("from apple.ball import *",
          python.ImportFrom("apple.ball", (python.alias("*", None), ), 0)),
     ])
Ejemplo n.º 2
0
 def test_from_module_import_names(self):
     self.template([
         ("from apple import ball",
          python.ImportFrom("apple", (python.alias("ball", None), ), 0)),
         ("from apple import ball as cat",
          python.ImportFrom("apple", (python.alias("ball", "cat"), ), 0)),
     ])
Ejemplo n.º 3
0
 def test_from_submodule_import_names(self):
     self.template([
         (
             "from apple.ball import (\n    cat, \n    dog,)",
             python.ImportFrom(
                 "apple.ball",
                 (
                     python.alias("cat", None),
                     python.alias("dog", None),
                 ),
                 0
             )
         ),
         (
             "from apple.ball import cat as dog",
             python.ImportFrom(
                 "apple.ball",
                 (
                     python.alias("cat", "dog"),
                 ),
                 0
             )
         ),
         (
             "from apple.ball import cat as dog, egg",
             python.ImportFrom(
                 "apple.ball",
                 (
                     python.alias("cat", "dog"),
                     python.alias("egg", None),
                 ),
                 0
             )
         ),
         (
             "from apple.ball import (\n    cat as dog, \n    egg as frog)",
             python.ImportFrom(
                 "apple.ball",
                 (
                     python.alias("cat", "dog"),
                     python.alias("egg", "frog"),
                 ),
                 0
             )
         ),
     ])
Ejemplo n.º 4
0
    def visit_ImportFrom(self, node):
        # We handle Future imports specially, although they do nothing in Py3!
        # Just incase we want to support Python 2!
        if node.module is "__future__" and not node.level:
            bail_out = False
            for feature in node.names:
                if not hasattr(future, feature.name):
                    self.log_error("__future__ has no feature {!r}".format(
                        feature.name))
                    bail_out = True
            if bail_out:
                return None

            return python.Future(node.names)

        return python.ImportFrom(node.module, node.names, node.level)