[Python-checkins] r69679 - in sandbox/trunk/2to3/lib2to3: fixer_util.py fixes/fix_set_literal.py pytree.py tests/test_pytree.py

benjamin.peterson python-checkins at python.org
Mon Feb 16 18:36:07 CET 2009


Author: benjamin.peterson
Date: Mon Feb 16 18:36:06 2009
New Revision: 69679

Log:
make Base.get_next_sibling() and Base.get_prev_sibling() properties

Modified:
   sandbox/trunk/2to3/lib2to3/fixer_util.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py
   sandbox/trunk/2to3/lib2to3/pytree.py
   sandbox/trunk/2to3/lib2to3/tests/test_pytree.py

Modified: sandbox/trunk/2to3/lib2to3/fixer_util.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixer_util.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixer_util.py	Mon Feb 16 18:36:06 2009
@@ -226,7 +226,7 @@
     """
     Check that something isn't an attribute or function name etc.
     """
-    prev = node.get_prev_sibling()
+    prev = node.prev_sibling
     if prev is not None and prev.type == token.DOT:
         # Attribute lookup.
         return False

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py	Mon Feb 16 18:36:06 2009
@@ -38,7 +38,7 @@
         literal.extend(n.clone() for n in items.children)
         literal.append(pytree.Leaf(token.RBRACE, "}"))
         # Set the prefix of the right brace to that of the ')' or ']'
-        literal[-1].set_prefix(items.get_next_sibling().get_prefix())
+        literal[-1].set_prefix(items.next_sibling.get_prefix())
         maker = pytree.Node(syms.dictsetmaker, literal)
         maker.set_prefix(node.get_prefix())
 

Modified: sandbox/trunk/2to3/lib2to3/pytree.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/pytree.py	(original)
+++ sandbox/trunk/2to3/lib2to3/pytree.py	Mon Feb 16 18:36:06 2009
@@ -162,10 +162,12 @@
                     self.parent = None
                     return i
 
-    def get_next_sibling(self):
-        """Return the node immediately following the invocant in their
-        parent's children list. If the invocant does not have a next
-        sibling, return None."""
+    @property
+    def next_sibling(self):
+        """
+        The node immediately following the invocant in their parent's children
+        list. If the invocant does not have a next sibling, it is None
+        """
         if self.parent is None:
             return None
 
@@ -177,10 +179,12 @@
                 except IndexError:
                     return None
 
-    def get_prev_sibling(self):
-        """Return the node immediately preceding the invocant in their
-        parent's children list. If the invocant does not have a previous
-        sibling, return None."""
+    @property
+    def prev_sibling(self):
+        """
+        The node immediately preceding the invocant in their parent's children
+        list. If the invocant does not have a previous sibling, it is None.
+        """
         if self.parent is None:
             return None
 
@@ -193,8 +197,8 @@
 
     def get_suffix(self):
         """Return the string immediately following the invocant node. This
-        is effectively equivalent to node.get_next_sibling().get_prefix()"""
-        next_sib = self.get_next_sibling()
+        is effectively equivalent to node.next_sibling.get_prefix()"""
+        next_sib = self.next_sibling
         if next_sib is None:
             return ""
         return next_sib.get_prefix()

Modified: sandbox/trunk/2to3/lib2to3/tests/test_pytree.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_pytree.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_pytree.py	Mon Feb 16 18:36:06 2009
@@ -306,36 +306,36 @@
         n2 = pytree.Node(1000, [])
         p1 = pytree.Node(1000, [n1, n2])
 
-        self.failUnless(n1.get_next_sibling() is n2)
-        self.assertEqual(n2.get_next_sibling(), None)
-        self.assertEqual(p1.get_next_sibling(), None)
+        self.failUnless(n1.next_sibling is n2)
+        self.assertEqual(n2.next_sibling, None)
+        self.assertEqual(p1.next_sibling, None)
 
     def testLeafNextSibling(self):
         l1 = pytree.Leaf(100, "a")
         l2 = pytree.Leaf(100, "b")
         p1 = pytree.Node(1000, [l1, l2])
 
-        self.failUnless(l1.get_next_sibling() is l2)
-        self.assertEqual(l2.get_next_sibling(), None)
-        self.assertEqual(p1.get_next_sibling(), None)
+        self.failUnless(l1.next_sibling is l2)
+        self.assertEqual(l2.next_sibling, None)
+        self.assertEqual(p1.next_sibling, None)
 
     def testNodePrevSibling(self):
         n1 = pytree.Node(1000, [])
         n2 = pytree.Node(1000, [])
         p1 = pytree.Node(1000, [n1, n2])
 
-        self.failUnless(n2.get_prev_sibling() is n1)
-        self.assertEqual(n1.get_prev_sibling(), None)
-        self.assertEqual(p1.get_prev_sibling(), None)
+        self.failUnless(n2.prev_sibling is n1)
+        self.assertEqual(n1.prev_sibling, None)
+        self.assertEqual(p1.prev_sibling, None)
 
     def testLeafPrevSibling(self):
         l1 = pytree.Leaf(100, "a")
         l2 = pytree.Leaf(100, "b")
         p1 = pytree.Node(1000, [l1, l2])
 
-        self.failUnless(l2.get_prev_sibling() is l1)
-        self.assertEqual(l1.get_prev_sibling(), None)
-        self.assertEqual(p1.get_prev_sibling(), None)
+        self.failUnless(l2.prev_sibling is l1)
+        self.assertEqual(l1.prev_sibling, None)
+        self.assertEqual(p1.prev_sibling, None)
 
 
 class TestPatterns(support.TestCase):


More information about the Python-checkins mailing list