"""Parser for future statements
from compiler import ast, walk
"""Return true if statement is a well-formed future statement"""
if not isinstance(stmt, ast.From):
if stmt.modname == "__future__":
features = ("nested_scopes", "generators", "division",
"absolute_import", "with_statement", "print_function",
def visitModule(self, node):
if not self.check_stmt(s):
def check_stmt(self, stmt):
for name, asname in stmt.names:
if name in self.features:
"future feature %s is not defined" % name
"""Return list of features enabled by future statements"""
"""Check for invalid future statements"""
def visitFrom(self, node):
if hasattr(node, 'valid_future'):
if node.modname != "__future__":
raise SyntaxError, "invalid future statement " + repr(node)
if __name__ == "__main__":
from compiler import parseFile, walk
for file in sys.argv[1:]: