biopython/biopython — pull request #230 by superbobry (2013-08-30 20:59:58+00:00)
Title: Partially migrated to print-function-like syntax

For now we only handle the 'print' statement with a single argument,
i. e.:

print ... -> print(...)

Migration was performed using a 2to3 fixer class:

from lib2to3 import fixer_base, patcomp
from lib2to3.fixer_util import Name, Call

parend_expr = patcomp.compile_pattern(
"""atom< '(' [atom|term|testlist_gexp|STRING|NAME] ')' >""")

class FixSinglePrint(fixer_base.BaseFix):
PATTERN = "print_stmt"
BM_compatible = True

def transform(self, node, results):
assert results
assert node.children[0] == Name(u"print")
args = node.children[1:]
if len(args) != 1 or parend_expr.match(args[0]):
# We only fix 'print' statements which have _exactly_ one
# non-parenthesized argument.
return

l_args = [arg.clone() for arg in args]
l_args[0].prefix = u""
n_stmt = Call(Name(u"print"), l_args)
n_stmt.prefix = node.prefix
return n_stmt