]> granicus.if.org Git - python/commitdiff
PEP 479: Use the return-keyword instead of raising StopIteration inside a generators.
authorRaymond Hettinger <python@rcn.com>
Sun, 23 Nov 2014 06:14:41 +0000 (22:14 -0800)
committerRaymond Hettinger <python@rcn.com>
Sun, 23 Nov 2014 06:14:41 +0000 (22:14 -0800)
Lib/ipaddress.py
Lib/mailbox.py
Lib/test/test_buffer.py
Lib/test/test_collections.py
Lib/test/test_itertools.py
Lib/test/test_sys_setprofile.py

index d15a1d923fcbfac30e7aa9a68faeb86d835d4282..b32a7e1dac2f8b7bc08525ad63cc2774870f7ef5 100644 (file)
@@ -808,7 +808,7 @@ class _BaseNetwork(_IPAddressBase):
                 other.broadcast_address <= self.broadcast_address):
             raise ValueError('%s not contained in %s' % (other, self))
         if other == self:
-            raise StopIteration
+            return
 
         # Make sure we're comparing the network of other.
         other = other.__class__('%s/%s' % (other.network_address,
index 145b2040c9b761f535c14b56a958b6f642de6d82..e7f31df1e53920ab65b370f74654c37957f36fd6 100644 (file)
@@ -1949,7 +1949,7 @@ class _ProxyFile:
         while True:
             line = self.readline()
             if not line:
-                raise StopIteration
+                return
             yield line
 
     def tell(self):
index 1667847a9df16b4e37f88050736a155d262dd877..1cdc771a9aa8be1f516e25e90656306b3d23f6a4 100644 (file)
@@ -216,7 +216,7 @@ def iter_format(nitems, testobj='ndarray'):
     for t in iter_mode(nitems, testobj):
         yield t
     if testobj != 'ndarray':
-        raise StopIteration
+        return
     yield struct_items(nitems, testobj)
 
 
index e948106c5855a0fa407de497f79b46d9fe642eb7..7b464752ed6bfd8c421b4babc00f9a6f78ecfc1a 100644 (file)
@@ -511,7 +511,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
         class NextOnly:
             def __next__(self):
                 yield 1
-                raise StopIteration
+                return
         self.assertNotIsInstance(NextOnly(), Iterator)
 
     def test_Sized(self):
index 5f33d3975edf80200614ff6b37756c85826af322..d48bf55f233354cf1574174f80eb9b4d0fb6c06c 100644 (file)
@@ -1803,8 +1803,6 @@ class RegressionTests(unittest.TestCase):
             hist.append(3)
             yield 2
             hist.append(4)
-            if x:
-                raise StopIteration
 
         hist = []
         self.assertRaises(AssertionError, list, chain(gen1(), gen2(False)))
index 9816e3ed6466b411cce23fc9f9056cbf34643e73..e59320b1588a2347f8d59780b42a64f40f3e5ee0 100644 (file)
@@ -260,7 +260,6 @@ class ProfileHookTestCase(TestCaseBase):
         def f():
             for i in range(2):
                 yield i
-            raise StopIteration
         def g(p):
             for i in f():
                 pass