changeset: 93543:e8b3083bb148 user: Raymond Hettinger date: Sat Nov 22 22:14:41 2014 -0800 files: 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 description: PEP 479: Use the return-keyword instead of raising StopIteration inside a generators. diff -r 9eb0d0eb0992 -r e8b3083bb148 Lib/ipaddress.py --- a/Lib/ipaddress.py Sat Nov 22 21:56:23 2014 -0800 +++ b/Lib/ipaddress.py Sat Nov 22 22:14:41 2014 -0800 @@ -808,7 +808,7 @@ 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, diff -r 9eb0d0eb0992 -r e8b3083bb148 Lib/mailbox.py --- a/Lib/mailbox.py Sat Nov 22 21:56:23 2014 -0800 +++ b/Lib/mailbox.py Sat Nov 22 22:14:41 2014 -0800 @@ -1949,7 +1949,7 @@ while True: line = self.readline() if not line: - raise StopIteration + return yield line def tell(self): diff -r 9eb0d0eb0992 -r e8b3083bb148 Lib/test/test_buffer.py --- a/Lib/test/test_buffer.py Sat Nov 22 21:56:23 2014 -0800 +++ b/Lib/test/test_buffer.py Sat Nov 22 22:14:41 2014 -0800 @@ -216,7 +216,7 @@ for t in iter_mode(nitems, testobj): yield t if testobj != 'ndarray': - raise StopIteration + return yield struct_items(nitems, testobj) diff -r 9eb0d0eb0992 -r e8b3083bb148 Lib/test/test_collections.py --- a/Lib/test/test_collections.py Sat Nov 22 21:56:23 2014 -0800 +++ b/Lib/test/test_collections.py Sat Nov 22 22:14:41 2014 -0800 @@ -511,7 +511,7 @@ class NextOnly: def __next__(self): yield 1 - raise StopIteration + return self.assertNotIsInstance(NextOnly(), Iterator) def test_Sized(self): diff -r 9eb0d0eb0992 -r e8b3083bb148 Lib/test/test_itertools.py --- a/Lib/test/test_itertools.py Sat Nov 22 21:56:23 2014 -0800 +++ b/Lib/test/test_itertools.py Sat Nov 22 22:14:41 2014 -0800 @@ -1803,8 +1803,6 @@ hist.append(3) yield 2 hist.append(4) - if x: - raise StopIteration hist = [] self.assertRaises(AssertionError, list, chain(gen1(), gen2(False))) diff -r 9eb0d0eb0992 -r e8b3083bb148 Lib/test/test_sys_setprofile.py --- a/Lib/test/test_sys_setprofile.py Sat Nov 22 21:56:23 2014 -0800 +++ b/Lib/test/test_sys_setprofile.py Sat Nov 22 22:14:41 2014 -0800 @@ -260,7 +260,6 @@ def f(): for i in range(2): yield i - raise StopIteration def g(p): for i in f(): pass