From 34d4762fa9c1f87ca83eaad523e2470e823de5b1 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 26 Nov 2017 12:37:23 -0800 Subject: [PATCH] Handle docstring AST attribute (new in Python 3.7). --- quixote/ptl/ptl_parse.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/quixote/ptl/ptl_parse.py b/quixote/ptl/ptl_parse.py index be63916..c257068 100644 --- a/quixote/ptl/ptl_parse.py +++ b/quixote/ptl/ptl_parse.py @@ -84,6 +84,14 @@ class TemplateTransformer(ast.NodeTransformer): assign = ast.Assign(targets=[assign_name], value=instance) ast.copy_location(assign, node) ast.fix_missing_locations(assign) + docstring = getattr(node, 'docstring', None) + if docstring: + # Python 3.7 adds a docstring attribute to FunctionDef + # bpo-29463: Add docstring field to some AST nodes. (#46) + docstring = ast.Expr(ast.Str(docstring)) + ast.copy_location(assign, docstring) + ast.fix_missing_locations(docstring) + node.body.insert(0, self.visit_Expr(docstring)) node.body.insert(0, assign) # return _q_output.getvalue()