Commits

Amaury Forgeot d'Arc  committed f403ac4

iterators now must implement the __next__ method.

  • Participants
  • Parent commits 3f9d7e9
  • Branches py3k

Comments (0)

Files changed (17)

File pypy/interpreter/baseobjspace.py

     ('coerce',          'coerce',    2, ['__coerce__', '__coerce__']),
     ('contains',        'contains',  2, ['__contains__']),
     ('iter',            'iter',      1, ['__iter__']),
-    ('next',            'next',      1, ['next']),
+    ('next',            'next',      1, ['__next__']),
 #    ('call',            'call',      3, ['__call__']),
     ('get',             'get',       3, ['__get__']),
     ('set',             'set',       3, ['__set__']),

File pypy/interpreter/typedef.py

 GeneratorIterator.typedef = TypeDef("generator",
     __repr__   = interp2app(GeneratorIterator.descr__repr__),
     __reduce__   = interp2app(GeneratorIterator.descr__reduce__),
-    next       = interp2app(GeneratorIterator.descr_next,
-                            descrmismatch='next'),
+    __next__   = interp2app(GeneratorIterator.descr_next,
+                            descrmismatch='__next__'),
     send       = interp2app(GeneratorIterator.descr_send,
                             descrmismatch='send'),
     throw      = interp2app(GeneratorIterator.descr_throw,

File pypy/module/__builtin__/functional.py

 W_Enumerate.typedef = TypeDef("enumerate",
     __new__=interp2app(W_Enumerate.descr___new__.im_func),
     __iter__=interp2app(W_Enumerate.descr___iter__),
-    next=interp2app(W_Enumerate.descr_next),
+    __next__=interp2app(W_Enumerate.descr_next),
     __reduce__=interp2app(W_Enumerate.descr___reduce__),
 )
 
 
 W_ReversedIterator.typedef = TypeDef("reversed",
     __iter__=interp2app(W_ReversedIterator.descr___iter__),
-    next=interp2app(W_ReversedIterator.descr_next),
+    __next__=interp2app(W_ReversedIterator.descr_next),
     __reduce__=interp2app(W_ReversedIterator.descr___reduce__),
 )
 
     __iter__        = interp2app(W_RangeIterator.descr_iter),
 # XXX __length_hint__()
 ##    __len__         = interp2app(W_RangeIterator.descr_len),
-    next            = interp2app(W_RangeIterator.descr_next),
+    __next__        = interp2app(W_RangeIterator.descr_next),
     __reduce__      = interp2app(W_RangeIterator.descr_reduce),
 )

File pypy/module/__builtin__/interp_classobj.py

                 space.w_TypeError,
                 space.wrap("iteration over non-sequence"))
         return space.newseqiter(self)
-    #XXX do I really need a next method? the old implementation had one, but I
-    # don't see the point
+    # XXX do I really need a __next__ method? the old implementation
+    # had one, but I don't see the point
 
     def descr_call(self, space, __args__):
         w_meth = self.getattr(space, '__call__')
             return space.w_NotImplemented
 
     def descr_next(self, space):
-        w_func = self.getattr(space, 'next', False)
+        w_func = self.getattr(space, '__next__', False)
         if w_func is None:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("instance has no next() method"))
+            raise OperationError(space.w_TypeError, space.wrap(
+                    "instance has no __next__() method"))
         return space.call_function(w_func)
 
     def descr_del(self, space):
     __contains__ = interp2app(W_InstanceObject.descr_contains),
     __pow__ = interp2app(W_InstanceObject.descr_pow),
     __rpow__ = interp2app(W_InstanceObject.descr_rpow),
-    next = interp2app(W_InstanceObject.descr_next),
+    __next__ = interp2app(W_InstanceObject.descr_next),
     __del__ = interp2app(W_InstanceObject.descr_del),
     __exit__ = interp2app(W_InstanceObject.descr_exit),
     __dict__ = dict_descr,

File pypy/module/_collections/interp_deque.py

 
 W_DequeIter.typedef = TypeDef("deque_iterator",
     __iter__ = interp2app(W_DequeIter.iter),
-    next = interp2app(W_DequeIter.next),
+    __next__ = interp2app(W_DequeIter.next),
 )
 W_DequeIter.typedef.acceptable_as_base_class = False
 
 
 W_DequeRevIter.typedef = TypeDef("deque_reverse_iterator",
     __iter__ = interp2app(W_DequeRevIter.iter),
-    next = interp2app(W_DequeRevIter.next),
+    __next__ = interp2app(W_DequeRevIter.next),
 )
 W_DequeRevIter.typedef.acceptable_as_base_class = False
 

File pypy/module/_file/interp_file.py

     def direct_flush(self):
         self.getstream().flush()
 
-    def direct_next(self):
+    def direct___next__(self):
         line = self.getstream().readline()
         if line == '':
             raise OperationError(self.space.w_StopIteration, self.space.w_None)
     _decl(locals(), "isatty",
         """isatty() -> true or false.  True if the file is connected to a tty device.""")
 
-    _decl(locals(), "next",
-        """next() -> the next line in the file, or raise StopIteration""")
+    _decl(locals(), "__next__",
+        """__next__() -> the next line in the file, or raise StopIteration""")
 
     _decl(locals(), "read",
         """read([size]) -> read at most size bytes, returned as a string.

File pypy/module/_io/interp_iobase.py

     __enter__ = interp2app(W_IOBase.enter_w),
     __exit__ = interp2app(W_IOBase.exit_w),
     __iter__ = interp2app(W_IOBase.iter_w),
-    next = interp2app(W_IOBase.next_w),
+    __next__ = interp2app(W_IOBase.next_w),
     close = interp2app(W_IOBase.close_w),
     flush = interp2app(W_IOBase.flush_w),
     tell = interp2app(W_IOBase.tell_w),

File pypy/module/_io/interp_textio.py

     __repr__ = interp2app(W_TextIOWrapper.descr_repr),
     __module__ = "_io",
 
-    next = interp2app(W_TextIOWrapper.next_w),
+    __next__ = interp2app(W_TextIOWrapper.next_w),
     read = interp2app(W_TextIOWrapper.read_w),
     readline = interp2app(W_TextIOWrapper.readline_w),
     write = interp2app(W_TextIOWrapper.write_w),

File pypy/module/_sre/interp_sre.py

 W_SRE_Scanner.typedef = TypeDef(
     'SRE_Scanner',
     __iter__ = interp2app(W_SRE_Scanner.iter_w),
-    next     = interp2app(W_SRE_Scanner.next_w),
+    __next__ = interp2app(W_SRE_Scanner.next_w),
     match    = interp2app(W_SRE_Scanner.match_w),
     search   = interp2app(W_SRE_Scanner.search_w),
     pattern  = interp_attrproperty('srepat', W_SRE_Scanner),

File pypy/module/cStringIO/interp_stringio.py

         self.check_closed()
         return self.space.w_False
 
-    def descr_next(self):
+    def descr___next__(self):
         space = self.space
         self.check_closed()
         line = self.readline()
 
 common_descrs = {
     '__iter__':     interp2app(W_InputOutputType.descr___iter__),
+    '__next__':     interp2app(W_InputOutputType.descr___next__),
     'close':        interp2app(W_InputOutputType.descr_close),
     'flush':        interp2app(W_InputOutputType.descr_flush),
     'getvalue':     interp2app(W_InputOutputType.descr_getvalue),
     'isatty':       interp2app(W_InputOutputType.descr_isatty),
-    'next':         interp2app(W_InputOutputType.descr_next),
     'read':         interp2app(W_InputOutputType.descr_read),
     'readline':     interp2app(W_InputOutputType.descr_readline),
     'readlines':    interp2app(W_InputOutputType.descr_readlines),

File pypy/module/cpyext/dictobject.py

         w_iter = space.call_method(w_dict, "iteritems")
         pos = ppos[0]
         while pos:
-            space.call_method(w_iter, "next")
+            space.next(w_iter)
             pos -= 1
 
-        w_item = space.call_method(w_iter, "next")
+        w_item = space.next(w_iter)
         w_key, w_value = space.fixedview(w_item, 2)
         state = space.fromcache(RefcountState)
         pkey[0]   = state.make_borrowed(w_dict, w_key)

File pypy/module/cpyext/iterator.py

 def PyIter_Check(space, w_obj):
     """Return true if the object o supports the iterator protocol."""
     try:
-        w_attr = space.getattr(space.type(w_obj), space.wrap("next"))
+        w_attr = space.getattr(space.type(w_obj), space.wrap("__next__"))
     except:
         return False
     else:

File pypy/module/cpyext/slotdefs.py

                "x.__ge__(y) <==> x>=y"),
         TPSLOT("__iter__", tp_iter, slot_tp_iter, wrap_unaryfunc,
                "x.__iter__() <==> iter(x)"),
-        TPSLOT("next", tp_iternext, slot_tp_iternext, wrap_next,
-               "x.next() -> the next value, or raise StopIteration"),
+        TPSLOT("__next__", tp_iternext, slot_tp_iternext, wrap_next,
+               "x.__next__() -> the next value, or raise StopIteration"),
         TPSLOT("__get__", tp_descr_get, slot_tp_descr_get, wrap_descr_get,
                "descr.__get__(obj[, type]) -> value"),
         TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set,

File pypy/module/exceptions/interp_exceptions.py

                             __str__ = key_error_str)
 
 W_StopIteration = _new_exception('StopIteration', W_Exception,
-                                 """Signal the end from iterator.next().""")
+                                 """Signal the end from iterator.__next__().""")
 
 W_Warning = _new_exception('Warning', W_Exception,
                            """Base class for warning categories.""")

File pypy/module/itertools/interp_itertools.py

         __module__ = 'itertools',
         __new__ = interp2app(W_Count___new__),
         __iter__ = interp2app(W_Count.iter_w),
-        next = interp2app(W_Count.next_w),
+        __next__ = interp2app(W_Count.next_w),
         __reduce__ = interp2app(W_Count.reduce_w),
         __repr__ = interp2app(W_Count.repr_w),
         __doc__ = """Make an iterator that returns consecutive integers starting
         __module__ = 'itertools',
         __new__  = interp2app(W_Repeat___new__),
         __iter__ = interp2app(W_Repeat.iter_w),
-        next     = interp2app(W_Repeat.next_w),
+        __next__ = interp2app(W_Repeat.next_w),
         __repr__ = interp2app(W_Repeat.repr_w),
         __doc__  = """Make an iterator that returns object over and over again.
     Runs indefinitely unless the times argument is specified.  Used
         __module__ = 'itertools',
         __new__  = interp2app(W_TakeWhile___new__),
         __iter__ = interp2app(W_TakeWhile.iter_w),
-        next     = interp2app(W_TakeWhile.next_w),
+        __next__ = interp2app(W_TakeWhile.next_w),
         __doc__  = """Make an iterator that returns elements from the iterable as
     long as the predicate is true.
 
         __module__ = 'itertools',
         __new__  = interp2app(W_DropWhile___new__),
         __iter__ = interp2app(W_DropWhile.iter_w),
-        next     = interp2app(W_DropWhile.next_w),
+        __next__ = interp2app(W_DropWhile.next_w),
         __doc__  = """Make an iterator that drops elements from the iterable as long
     as the predicate is true; afterwards, returns every
     element. Note, the iterator does not produce any output until the
         __module__ = 'itertools',
         __new__  = interp2app(W_IFilter___new__),
         __iter__ = interp2app(W_IFilter.iter_w),
-        next     = interp2app(W_IFilter.next_w),
+        __next__ = interp2app(W_IFilter.next_w),
         __doc__  = """Make an iterator that filters elements from iterable returning
     only those for which the predicate is True.  If predicate is
     None, return the items that are true.
         __module__ = 'itertools',
         __new__  = interp2app(W_IFilterFalse___new__),
         __iter__ = interp2app(W_IFilterFalse.iter_w),
-        next     = interp2app(W_IFilterFalse.next_w),
+        __next__ = interp2app(W_IFilterFalse.next_w),
         __doc__  = """Make an iterator that filters elements from iterable returning
     only those for which the predicate is False.  If predicate is
     None, return the items that are false.
         __module__ = 'itertools',
         __new__  = interp2app(W_ISlice___new__),
         __iter__ = interp2app(W_ISlice.iter_w),
-        next     = interp2app(W_ISlice.next_w),
+        __next__ = interp2app(W_ISlice.next_w),
         __doc__  = """Make an iterator that returns selected elements from the
     iterable.  If start is non-zero, then elements from the iterable
     are skipped until start is reached. Afterward, elements are
         __module__ = 'itertools',
         __new__  = interp2app(W_Chain___new__),
         __iter__ = interp2app(W_Chain.iter_w),
-        next     = interp2app(W_Chain.next_w),
+        __next__ = interp2app(W_Chain.next_w),
         from_iterable = interp2app(chain_from_iterable, as_classmethod=True),
         __doc__  = """Make an iterator that returns elements from the first iterable
     until it is exhausted, then proceeds to the next iterable, until
         __module__ = 'itertools',
         __new__  = interp2app(W_IMap___new__),
         __iter__ = interp2app(W_IMap.iter_w),
-        next     = interp2app(W_IMap.next_w),
+        __next__ = interp2app(W_IMap.next_w),
         __doc__  = """Make an iterator that computes the function using arguments
     from each of the iterables. If function is set to None, then
     imap() returns the arguments as a tuple. Like map() but stops
         __module__ = 'itertools',
         __new__  = interp2app(W_IZip___new__),
         __iter__ = interp2app(W_IZip.iter_w),
-        next     = interp2app(W_IZip.next_w),
+        __next__ = interp2app(W_IZip.next_w),
         __doc__  = """Make an iterator that aggregates elements from each of the
     iterables.  Like zip() except that it returns an iterator instead
     of a list. Used for lock-step iteration over several iterables at
         __module__ = 'itertools',
         __new__  = interp2app(W_IZipLongest___new__),
         __iter__ = interp2app(W_IZipLongest.iter_w),
-        next     = interp2app(W_IZipLongest.next_w),
+        __next__ = interp2app(W_IZipLongest.next_w),
         __doc__  = """Return an izip_longest object whose .next() method returns a tuple where
     the i-th element comes from the i-th iterable argument.  The .next()
     method continues until the longest iterable in the argument sequence
         __module__ = 'itertools',
         __new__  = interp2app(W_Cycle___new__),
         __iter__ = interp2app(W_Cycle.iter_w),
-        next     = interp2app(W_Cycle.next_w),
+        __next__ = interp2app(W_Cycle.next_w),
         __doc__  = """Make an iterator returning elements from the iterable and
     saving a copy of each. When the iterable is exhausted, return
     elements from the saved copy. Repeats indefinitely.
         __module__ = 'itertools',
         __new__  = interp2app(W_StarMap___new__),
         __iter__ = interp2app(W_StarMap.iter_w),
-        next     = interp2app(W_StarMap.next_w),
+        __next__ = interp2app(W_StarMap.next_w),
         __doc__  = """Make an iterator that computes the function using arguments
     tuples obtained from the iterable. Used instead of imap() when
     argument parameters are already grouped in tuples from a single
         __module__ = 'itertools',
         __new__ = interp2app(W_TeeIterable___new__),
         __iter__ = interp2app(W_TeeIterable.iter_w),
-        next     = interp2app(W_TeeIterable.next_w),
+        __next__ = interp2app(W_TeeIterable.next_w),
         __weakref__ = make_weakref_descr(W_TeeIterable),
         )
 W_TeeIterable.typedef.acceptable_as_base_class = False
         __module__ = 'itertools',
         __new__  = interp2app(W_GroupBy___new__),
         __iter__ = interp2app(W_GroupBy.iter_w),
-        next     = interp2app(W_GroupBy.next_w),
+        __next__ = interp2app(W_GroupBy.next_w),
         __doc__  = """Make an iterator that returns consecutive keys and groups from the
     iterable. The key is a function computing a key value for each
     element. If not specified or is None, key defaults to an identity
         '_groupby',
         __module__ = 'itertools',
         __iter__ = interp2app(W_GroupByIterator.iter_w),
-        next     = interp2app(W_GroupByIterator.next_w))
+        __next__ = interp2app(W_GroupByIterator.next_w))
 W_GroupByIterator.typedef.acceptable_as_base_class = False
 
 
     __module__ = 'itertools',
     __new__ = interp2app(W_Compress__new__),
     __iter__ = interp2app(W_Compress.iter_w),
-    next     = interp2app(W_Compress.next_w),
+    __next__ = interp2app(W_Compress.next_w),
     __doc__ = """Make an iterator that filters elements from *data* returning
    only those that have a corresponding element in *selectors* that evaluates to
    ``True``.  Stops when either the *data* or *selectors* iterables has been
     __module__ = 'itertools',
     __new__ = interp2app(W_Product__new__),
     __iter__ = interp2app(W_Product.iter_w),
-    next = interp2app(W_Product.next_w),
+    __next__ = interp2app(W_Product.next_w),
     __doc__ = """
    Cartesian product of input iterables.
 
     __module__ = 'itertools',
     __new__ = interp2app(W_Combinations__new__),
     __iter__ = interp2app(W_Combinations.descr__iter__),
-    next = interp2app(W_Combinations.descr_next),
+    __next__ = interp2app(W_Combinations.descr_next),
     __doc__ = """\
 combinations(iterable, r) --> combinations object
 
     __module__ = 'itertools',
     __new__ = interp2app(W_CombinationsWithReplacement__new__),
     __iter__ = interp2app(W_CombinationsWithReplacement.descr__iter__),
-    next = interp2app(W_CombinationsWithReplacement.descr_next),
+    __next__ = interp2app(W_CombinationsWithReplacement.descr_next),
     __doc__ = """\
 combinations_with_replacement(iterable, r) --> combinations_with_replacement object
 
     __module__ = 'itertools',
     __new__ = interp2app(W_Permutations__new__),
     __iter__ = interp2app(W_Permutations.descr__iter__),
-    next = interp2app(W_Permutations.descr_next),
+    __next__ = interp2app(W_Permutations.descr_next),
     __doc__ = """\
 permutations(iterable[, r]) --> permutations object
 

File pypy/module/oracle/interp_cursor.py

     setoutputsize = interp2app(W_Cursor.setoutputsize),
 
     __iter__ = interp2app(W_Cursor.descr_iter),
-    next = interp2app(W_Cursor.descr_next),
+    __next__ = interp2app(W_Cursor.descr_next),
 
     arraysize = GetSetProperty(W_Cursor.arraysize_get,
                                W_Cursor.arraysize_set),

File pypy/objspace/descroperation.py

                                       typename)
             return space.newseqiter(w_obj)
         w_iter = space.get_and_call_function(w_descr, w_obj)
-        w_next = space.lookup(w_iter, 'next')
+        w_next = space.lookup(w_iter, '__next__')
         if w_next is None:
             raise OperationError(space.w_TypeError,
                                  space.wrap("iter() returned non-iterator"))
         return w_iter
 
     def next(space, w_obj):
-        w_descr = space.lookup(w_obj, 'next')
+        w_descr = space.lookup(w_obj, '__next__')
         if w_descr is None:
             typename = space.type(w_obj).getname(space)
             raise operationerrfmt(space.w_TypeError,