Kaydet (Commit) bb6c0aae authored tarafından Raymond Hettinger's avatar Raymond Hettinger

PEP 479: Use the return-keyword instead of raising StopIteration inside a generators.

üst 828d932a
...@@ -808,7 +808,7 @@ class _BaseNetwork(_IPAddressBase): ...@@ -808,7 +808,7 @@ class _BaseNetwork(_IPAddressBase):
other.broadcast_address <= self.broadcast_address): other.broadcast_address <= self.broadcast_address):
raise ValueError('%s not contained in %s' % (other, self)) raise ValueError('%s not contained in %s' % (other, self))
if other == self: if other == self:
raise StopIteration return
# Make sure we're comparing the network of other. # Make sure we're comparing the network of other.
other = other.__class__('%s/%s' % (other.network_address, other = other.__class__('%s/%s' % (other.network_address,
......
...@@ -1949,7 +1949,7 @@ class _ProxyFile: ...@@ -1949,7 +1949,7 @@ class _ProxyFile:
while True: while True:
line = self.readline() line = self.readline()
if not line: if not line:
raise StopIteration return
yield line yield line
def tell(self): def tell(self):
......
...@@ -216,7 +216,7 @@ def iter_format(nitems, testobj='ndarray'): ...@@ -216,7 +216,7 @@ def iter_format(nitems, testobj='ndarray'):
for t in iter_mode(nitems, testobj): for t in iter_mode(nitems, testobj):
yield t yield t
if testobj != 'ndarray': if testobj != 'ndarray':
raise StopIteration return
yield struct_items(nitems, testobj) yield struct_items(nitems, testobj)
......
...@@ -511,7 +511,7 @@ class TestOneTrickPonyABCs(ABCTestCase): ...@@ -511,7 +511,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
class NextOnly: class NextOnly:
def __next__(self): def __next__(self):
yield 1 yield 1
raise StopIteration return
self.assertNotIsInstance(NextOnly(), Iterator) self.assertNotIsInstance(NextOnly(), Iterator)
def test_Sized(self): def test_Sized(self):
......
...@@ -1803,8 +1803,6 @@ class RegressionTests(unittest.TestCase): ...@@ -1803,8 +1803,6 @@ class RegressionTests(unittest.TestCase):
hist.append(3) hist.append(3)
yield 2 yield 2
hist.append(4) hist.append(4)
if x:
raise StopIteration
hist = [] hist = []
self.assertRaises(AssertionError, list, chain(gen1(), gen2(False))) self.assertRaises(AssertionError, list, chain(gen1(), gen2(False)))
......
...@@ -260,7 +260,6 @@ class ProfileHookTestCase(TestCaseBase): ...@@ -260,7 +260,6 @@ class ProfileHookTestCase(TestCaseBase):
def f(): def f():
for i in range(2): for i in range(2):
yield i yield i
raise StopIteration
def g(p): def g(p):
for i in f(): for i in f():
pass pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment