changeset 25254:060bdfef2517

parser: extract closure of prettyformat() to a top-level function There was no capture until I added 'leafnodes' argument.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 06 May 2015 10:17:41 +0900
parents 3f1a9b44b8c2
children ad1d2c952889
files mercurial/parser.py
diffstat 1 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parser.py	Sun Apr 26 22:20:03 2015 +0900
+++ b/mercurial/parser.py	Wed May 06 10:17:41 2015 +0900
@@ -94,17 +94,17 @@
             return self.eval(t)
         return t
 
+def _prettyformat(tree, leafnodes, level, lines):
+    if not isinstance(tree, tuple) or tree[0] in leafnodes:
+        lines.append((level, str(tree)))
+    else:
+        lines.append((level, '(%s' % tree[0]))
+        for s in tree[1:]:
+            _prettyformat(s, leafnodes, level + 1, lines)
+        lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
+
 def prettyformat(tree, leafnodes):
-    def _prettyformat(tree, level, lines):
-        if not isinstance(tree, tuple) or tree[0] in leafnodes:
-            lines.append((level, str(tree)))
-        else:
-            lines.append((level, '(%s' % tree[0]))
-            for s in tree[1:]:
-                _prettyformat(s, level + 1, lines)
-            lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')]
-
     lines = []
-    _prettyformat(tree, 0, lines)
+    _prettyformat(tree, leafnodes, 0, lines)
     output = '\n'.join(('  ' * l + s) for l, s in lines)
     return output