def transform(self, node, results): if self.skip: return libmodernize.add_future(node, "division") if node.value == "/": return pytree.Leaf(token.DOUBLESLASH, "//", prefix=node.prefix) else: return pytree.Leaf(token.DOUBLESLASHEQUAL, "//=", prefix=node.prefix)
def transform(self, node, results): if self.skip: return libmodernize.add_future(node, u'division') if node.value == '/': return pytree.Leaf(token.DOUBLESLASH, '//', prefix=node.prefix) else: return pytree.Leaf(token.DOUBLESLASHEQUAL, '//=', prefix=node.prefix)
def transform(self, node, results): if self.skip: return # We're not interested in __future__ imports here if (node.type == syms.import_from and getattr(results["imp"], "value", None) == "__future__"): return # If there are any non-future imports, add absolute_import libmodernize.add_future(node, "absolute_import") return super().transform(node, results)
def transform(self, node, results): if self.skip: return # We're not interested in __future__ imports here if node.type == syms.import_from \ and getattr(results['imp'], 'value', None) == '__future__': return # If there are any non-future imports, add absolute_import libmodernize.add_future(node, 'absolute_import') return super(FixImport, self).transform(node, results)
def transform(self, node, results): assert results bare_print = results.get("bare") if bare_print: # Special-case print all by itself bare_print.replace(Call(Name(u"print"), [], prefix=bare_print.prefix)) return assert node.children[0] == Name(u"print") args = node.children[1:] if len(args) == 1 and parend_expr.match(args[0]): # We don't want to keep sticking parens around an # already-parenthesised expression. return sep = end = file = None if args and args[-1] == Comma(): args = args[:-1] end = " " if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, u">>"): assert len(args) >= 2 file = args[1].clone() args = args[3:] # Strip a possible comma after the file expression # Now synthesize a print(args, sep=..., end=..., file=...) node. l_args = [arg.clone() for arg in args] if l_args: l_args[0].prefix = u"" if sep is not None or end is not None or file is not None: if sep is not None: self.add_kwarg(l_args, u"sep", String(repr(sep))) if end is not None: self.add_kwarg(l_args, u"end", String(repr(end))) if file is not None: self.add_kwarg(l_args, u"file", file) n_stmt = Call(Name(u"print"), l_args) n_stmt.prefix = node.prefix add_future(node, u'print_function') return n_stmt
def transform(self, node, results): assert results bare_print = results.get("bare") if bare_print: # Special-case print all by itself bare_print.replace( Call(Name(u"print"), [], prefix=bare_print.prefix)) return assert node.children[0] == Name(u"print") args = node.children[1:] if len(args) == 1 and parend_expr.match(args[0]): # We don't want to keep sticking parens around an # already-parenthesised expression. return sep = end = file = None if args and args[-1] == Comma(): args = args[:-1] end = " " if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, u">>"): assert len(args) >= 2 file = args[1].clone() args = args[3:] # Strip a possible comma after the file expression # Now synthesize a print(args, sep=..., end=..., file=...) node. l_args = [arg.clone() for arg in args] if l_args: l_args[0].prefix = u"" if sep is not None or end is not None or file is not None: if sep is not None: self.add_kwarg(l_args, u"sep", String(repr(sep))) if end is not None: self.add_kwarg(l_args, u"end", String(repr(end))) if file is not None: self.add_kwarg(l_args, u"file", file) n_stmt = Call(Name(u"print"), l_args) n_stmt.prefix = node.prefix add_future(node, u'print_function') return n_stmt
def transform(self, node, results): res = super(FixUnicodeFuture, self).transform(node, results) if res: add_future(node, 'unicode_literals') return res
def transform(self, node, results): result = super().transform(node, results) libmodernize.add_future(node, "print_function") return result
def transform(self, node, results): result = super(FixPrint, self).transform(node, results) libmodernize.add_future(node, u'print_function') return result
def transform(self, node, results): res = super().transform(node, results) if res: add_future(node, "unicode_literals") return res
def finish_tree(self, tree, name): if tree.children: add_future(tree, 'absolute_import')
def transform(self, node, results): if self.skip: return libmodernize.add_future(node, u'division') return pytree.Leaf(token.SLASH, "//", prefix=node.prefix)