]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix compiler.ast.flatten function so that it works on lists.
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Thu, 2 Jun 2005 05:55:20 +0000 (05:55 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Thu, 2 Jun 2005 05:55:20 +0000 (05:55 +0000)
Lib/compiler/ast.py
Lib/test/test_compiler.py
Tools/compiler/astgen.py

index 6b78fddcd42a62e6201cd52fad9d922962cecc2d..accda459e5dd25a2bb0fce87bdedcd67803b36c0 100644 (file)
@@ -4,9 +4,9 @@ This file is automatically generated by Tools/compiler/astgen.py
 """
 from consts import CO_VARARGS, CO_VARKEYWORDS
 
-def flatten(list):
+def flatten(seq):
     l = []
-    for elt in list:
+    for elt in seq:
         t = type(elt)
         if t is tuple or t is list:
             for elt2 in flatten(elt):
@@ -15,8 +15,8 @@ def flatten(list):
             l.append(elt)
     return l
 
-def flatten_nodes(list):
-    return [n for n in flatten(list) if isinstance(n, Node)]
+def flatten_nodes(seq):
+    return [n for n in flatten(seq) if isinstance(n, Node)]
 
 nodes = {}
 
index 32302a19c22f45b755b8629e05889bdd2b03e760..6bfe225e7bb3b7f55e5c6a1b186b73f8c6e7b8e8 100644 (file)
@@ -1,4 +1,5 @@
 import compiler
+from compiler.ast import flatten
 import os
 import test.test_support
 import unittest
@@ -60,6 +61,10 @@ class CompilerTest(unittest.TestCase):
         for child in node.getChildNodes():
             self.check_lineno(child)
 
+    def testFlatten(self):
+        self.assertEquals(flatten([1, [2]]), [1, 2])
+        self.assertEquals(flatten((1, (2,))), [1, 2])
+
 NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)
 
 ###############################################################################
index 4ccc54d638565941a834d441b8a0e95d25f10894..e6aa35030d492249a86510bcccd407667d3e6bdc 100644 (file)
@@ -234,9 +234,9 @@ This file is automatically generated by Tools/compiler/astgen.py
 """
 from consts import CO_VARARGS, CO_VARKEYWORDS
 
-def flatten(list):
+def flatten(seq):
     l = []
-    for elt in list:
+    for elt in seq:
         t = type(elt)
         if t is tuple or t is list:
             for elt2 in flatten(elt):
@@ -245,8 +245,8 @@ def flatten(list):
             l.append(elt)
     return l
 
-def flatten_nodes(list):
-    return [n for n in flatten(list) if isinstance(n, Node)]
+def flatten_nodes(seq):
+    return [n for n in flatten(seq) if isinstance(n, Node)]
 
 nodes = {}