[py3k] next(iterator) instead of iterator.next()
authorRémi Cardona <remi.cardona@free.fr>
Fri, 25 Jul 2014 00:28:13 +0200
changeset 755 e71e8fa36c64
parent 754 95fb0ae31439
child 756 88264491da44
[py3k] next(iterator) instead of iterator.next() Requires python >= 2.6.
nodes.py
stcheck.py
stmts.py
test/unittest_nodes.py
test/unittest_utils.py
--- a/nodes.py	Fri Jul 25 00:26:37 2014 +0200
+++ b/nodes.py	Fri Jul 25 00:28:13 2014 +0200
@@ -144,7 +144,7 @@
             for atype in sorted(value):
                 infunc.append(Constant(atype, ctype))
             return rel
-        value = iter(value).next()
+        value = next(iter(value))
     return make_relation(var, rtype, (value, ctype), Constant, operator)
 
 
@@ -1023,11 +1023,11 @@
                 context = None
                 if lhsvar is not None and mainindex in lhsvar.stinfo['selected']:
                     if len(lhsvar.stinfo['possibletypes']) == 1:
-                        context = iter(lhsvar.stinfo['possibletypes']).next()
+                        context = next(iter(lhsvar.stinfo['possibletypes']))
                     return tr(rtype, context=context)
                 if rhsvar is not None and mainindex in rhsvar.stinfo['selected']:
                     if len(rhsvar.stinfo['possibletypes']) == 1:
-                        context = iter(rhsvar.stinfo['possibletypes']).next()
+                        context = next(iter(rhsvar.stinfo['possibletypes']))
                     if schema is not None and rschema.symmetric:
                         return tr(rtype, context=context)
                     return tr(rtype + '_object', context=context)
@@ -1048,7 +1048,7 @@
         """
         if not self.stinfo['selected']:
             return None
-        return iter(self.stinfo['selected']).next()
+        return next(iter(self.stinfo['selected']))
 
     def main_relation(self):
         """Return the relation where this variable is used in the rhs.
--- a/stcheck.py	Fri Jul 25 00:26:37 2014 +0200
+++ b/stcheck.py	Fri Jul 25 00:28:13 2014 +0200
@@ -579,7 +579,7 @@
                         stinfo['attrvars'].remove( (lhsvar, rel.r_type) )
                         if stinfo['attrvar'] is lhsvar:
                             if stinfo['attrvars']:
-                                stinfo['attrvar'] = iter(stinfo['attrvars']).next()
+                                stinfo['attrvar'] = next(iter(stinfo['attrvars']))
                             else:
                                 stinfo['attrvar'] = None
                     stinfo['rhsrelations'].remove(rel)
--- a/stmts.py	Fri Jul 25 00:26:37 2014 +0200
+++ b/stmts.py	Fri Jul 25 00:28:13 2014 +0200
@@ -120,7 +120,7 @@
             self._varmaker = rqlvar_maker(defined=self.defined_vars,
                                           # XXX only on Select node
                                           aliases=getattr(self, 'aliases', None))
-        return self._varmaker.next()
+        return next(self._varmaker)
 
     def make_variable(self):
         """create a new variable with an unique name for this tree"""
--- a/test/unittest_nodes.py	Fri Jul 25 00:26:37 2014 +0200
+++ b/test/unittest_nodes.py	Fri Jul 25 00:28:13 2014 +0200
@@ -67,7 +67,7 @@
     def test_add_is_type_restriction(self):
         tree = self.parse("Any X WHERE X is Person, X name ILIKE 'A%'")
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         self.assertRaises(RQLException, select.add_type_restriction, x.variable, 'Babar')
         select.add_type_restriction(x.variable, 'Person')
         self.assertEqual(tree.as_string(), "Any X WHERE X is Person, X name ILIKE 'A%'")
@@ -75,7 +75,7 @@
     def test_add_new_is_type_restriction_in(self):
         tree = self.parse("Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         select.add_type_restriction(x.variable, 'Company')
         # implementation is KISS (the IN remains)
         self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Company), X name ILIKE 'A%'")
@@ -83,27 +83,27 @@
     def test_add_new_is_type_restriction_in_nonregr(self):
         tree = self.parse('Any X WHERE X is IN(Person, Company, Student)')
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         select.add_type_restriction(x.variable, 'Person')
         self.assertEqual(tree.as_string(), 'Any X WHERE X is IN(Person)')
 
     def test_add_is_in_type_restriction(self):
         tree = self.parse("Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         self.assertRaises(RQLException, select.add_type_restriction, x.variable, 'Babar')
         self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
 
     def test_add_is_type_restriction_on_is_instance_of(self):
         select = self.parse("Any X WHERE X is_instance_of Person, X name ILIKE 'A%'").children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         select.add_type_restriction(x.variable, 'Person')
         self.assertEqual(select.as_string(), "Any X WHERE X name ILIKE 'A%', X is Person")
 
     def test_add_new_is_type_restriction_in_on_is_instance_of(self):
         tree = self.parse("Any X WHERE X is_instance_of IN(Person, Company), X name ILIKE 'A%'")
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         select.add_type_restriction(x.variable, 'Company')
         self.assertEqual(tree.as_string(), "Any X WHERE X name ILIKE 'A%', X is Company")
 
@@ -312,7 +312,7 @@
         annotator.annotate(tree) # needed to get typerel index
         tree.save_state()
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         select.add_type_restriction(x.variable, 'Company')
         self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Company), X name ILIKE 'A%'")
         tree.recover()
@@ -324,7 +324,7 @@
         annotator.annotate(tree) # needed to get typerel index
         tree.save_state()
         select = tree.children[0]
-        x = select.get_selected_variables().next()
+        x = next(select.get_selected_variables())
         select.add_type_restriction(x.variable, 'Company')
         self.assertEqual(tree.as_string(), "Any X WHERE X name ILIKE 'A%', X is Company")
         tree.recover()
--- a/test/unittest_utils.py	Fri Jul 25 00:26:37 2014 +0200
+++ b/test/unittest_utils.py	Fri Jul 25 00:28:13 2014 +0200
@@ -64,12 +64,12 @@
 
     def test_rqlvar_maker_dontstop(self):
         varlist = utils.rqlvar_maker()
-        self.assertEqual(varlist.next(), 'A')
-        self.assertEqual(varlist.next(), 'B')
+        self.assertEqual(next(varlist), 'A')
+        self.assertEqual(next(varlist), 'B')
         for i in range(24):
-            varlist.next()
-        self.assertEqual(varlist.next(), 'AA')
-        self.assertEqual(varlist.next(), 'AB')
+            next(varlist)
+        self.assertEqual(next(varlist), 'AA')
+        self.assertEqual(next(varlist), 'AB')
 
         
 if __name__ == '__main__':