[Python-checkins] r54515 - sandbox/trunk/2to3/fixes/util.py

collin.winter python-checkins at python.org
Wed Mar 21 23:59:43 CET 2007


Author: collin.winter
Date: Wed Mar 21 23:59:39 2007
New Revision: 54515

Modified:
   sandbox/trunk/2to3/fixes/util.py
Log:
Add is_list() to complement is_tuple().

Modified: sandbox/trunk/2to3/fixes/util.py
==============================================================================
--- sandbox/trunk/2to3/fixes/util.py	(original)
+++ sandbox/trunk/2to3/fixes/util.py	Wed Mar 21 23:59:39 2007
@@ -69,10 +69,18 @@
 
 def is_tuple(node):
     """Does the node represent a tuple literal?"""
-    
+    return _is_seq_literal(node, "(", ")")
+
+def is_list(node):
+    """Does the node represent a list literal?"""
+    return _is_seq_literal(node, "[", "]")
+           
+def _is_seq_literal(node, first, last):
+    """Abstract common parts of is_list, is_tuple"""
     return (isinstance(node, Node)
            and len(node.children) > 1
            and isinstance(node.children[0], Leaf)
            and isinstance(node.children[-1], Leaf)
-           and node.children[0].value == "("
-           and node.children[-1].value == ")")
+           and node.children[0].value == first
+           and node.children[-1].value == last)
+    


More information about the Python-checkins mailing list