diff options
author | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2005-06-02 05:55:20 (GMT) |
---|---|---|
committer | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2005-06-02 05:55:20 (GMT) |
commit | f36947032f4e99b2c55fc25fa36a1960c4423cbb (patch) | |
tree | 68a6122f3415232b331b59a408e469b7d728063a /Lib | |
parent | 76276177dea7d3e1412390e36a2c260f3f8107cb (diff) | |
download | cpython-f36947032f4e99b2c55fc25fa36a1960c4423cbb.zip cpython-f36947032f4e99b2c55fc25fa36a1960c4423cbb.tar.gz cpython-f36947032f4e99b2c55fc25fa36a1960c4423cbb.tar.bz2 |
Fix compiler.ast.flatten function so that it works on lists.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/compiler/ast.py | 8 | ||||
-rw-r--r-- | Lib/test/test_compiler.py | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py index 6b78fdd..accda45 100644 --- a/Lib/compiler/ast.py +++ b/Lib/compiler/ast.py @@ -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 = {} diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index 32302a1..6bfe225 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -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) ############################################################################### |