예제 #1
0
    def finish_tree(self, tree, filename):
        if not self.found_print:
            return

        for node in tree.children:
            if 'print_function' in check_future_import(node):
                # already imported
                return

        add_future_import('print_function', tree)
예제 #2
0
    def finish_tree(self, tree, name):
        super(FixUnicodeFuture, self).finish_tree(tree, name)

        if not self.found_unicode:
            return

        for node in tree.children:
            if 'unicode_literals' in check_future_import(node):
                return

        add_future_import(tree, 'unicode_literals')
    def finish_tree(self, tree, name):
        super(FixAbsoluteImportFuture, self).finish_tree(tree, name)

        for node in tree.children:
            if "absolute_import" in check_future_import(node):
                return

            if not (node.type == python_symbols.simple_stmt and node.children):
                continue

            # Only add future import if there exists imports in the file.
            # Otherwise we end up with a lot of useless clutter.
            node = node.children[0]
            if node.type == python_symbols.import_name or (
                node.type == python_symbols.import_from
                and node.children[1].type == token.NAME
                and node.children[1].value != "__future__"
            ):
                add_future_import(tree, "absolute_import")
                return