diff --git a/pytools/py_codegen.py b/pytools/py_codegen.py
index 5c90be9dea7f088cad76eb722d6fd0b6e5de7a5b..c8b7d057f2e17b125f6525f0734b2d8ff9684b9a 100644
--- a/pytools/py_codegen.py
+++ b/pytools/py_codegen.py
@@ -86,7 +86,7 @@ class PythonFunctionGenerator(PythonCodeGenerator):
     def get_function(self):
         result_dict = {}
         source_text = self.get()
-        exec(compile(source_text, "<generated function %s>" % self.name, "exec"),
+        exec(compile(source_text.rstrip()+"\n", "<generated function %s>" % self.name, "exec"),
                 result_dict)
         func = result_dict[self.name]
         result_dict["_MODULE_SOURCE_CODE"] = source_text