mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-22 22:23:39 +00:00
Merge pull request #4153 from Gallaecio/lgtm
MutableChain: return self from __iter__
This commit is contained in:
commit
65e2fb7d89
@ -383,9 +383,11 @@ class MutableChain(object):
|
||||
self.data = chain(self.data, *iterables)
|
||||
|
||||
def __iter__(self):
|
||||
return self.data.__iter__()
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
return next(self.data)
|
||||
|
||||
next = __next__
|
||||
@deprecated("scrapy.utils.python.MutableChain.__next__")
|
||||
def next(self):
|
||||
return self.__next__()
|
||||
|
@ -5,6 +5,7 @@ import unittest
|
||||
from itertools import count
|
||||
import platform
|
||||
import six
|
||||
from warnings import catch_warnings
|
||||
|
||||
from scrapy.utils.python import (
|
||||
memoizemethod_noargs, binary_is_text, equal_attributes,
|
||||
@ -21,8 +22,12 @@ class MutableChainTest(unittest.TestCase):
|
||||
m.extend([7, 8])
|
||||
m.extend([9, 10], (11, 12))
|
||||
self.assertEqual(next(m), 0)
|
||||
self.assertEqual(m.next(), 1)
|
||||
self.assertEqual(m.__next__(), 2)
|
||||
self.assertEqual(m.__next__(), 1)
|
||||
with catch_warnings(record=True) as warnings:
|
||||
self.assertEqual(m.next(), 2)
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertIn('scrapy.utils.python.MutableChain.__next__',
|
||||
str(warnings[0].message))
|
||||
self.assertEqual(list(m), list(range(3, 13)))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user