Skip to content

Commit 6eca2c1

Browse files
[stop-iteration-return] Use the multiple files template
1 parent 53025fd commit 6eca2c1

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def fruit_generator():
2+
for fruit in ["apple", "banana"]:
3+
yield fruit
4+
raise StopIteration # [stop-iteration-return]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def two_fruits_generator(fruits):
2+
for fruit in fruits:
3+
yield fruit, next(fruits) # [stop-iteration-return]

doc/data/messages/s/stop-iteration-return/bad.py renamed to doc/data/messages/s/stop-iteration-return/bad/two_good_fruit_generator.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
def fruit_generator():
2-
for fruit in ["apple", "banana"]:
3-
yield fruit
4-
raise StopIteration # [stop-iteration-return]
5-
6-
7-
def two_fruits_generator(fruits):
8-
for fruit in fruits:
9-
yield fruit, next(fruits) # [stop-iteration-return]
10-
11-
121
def two_good_fruits_generator(fruits):
132
for fruit in fruits:
143
if not fruit.is_tasty():
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def fruit_generator():
2+
"""The example is simple enough you don't need an explicit return."""
3+
for fruit in ["apple", "banana"]:
4+
yield fruit
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def two_fruits_generator(fruits):
2+
"""Catching the StopIteration."""
3+
for fruit in fruits:
4+
try:
5+
yield fruit, next(fruits)
6+
except StopIteration:
7+
print("Sorry there is only one fruit left.")
8+
yield fruit, None

doc/data/messages/s/stop-iteration-return/good.py renamed to doc/data/messages/s/stop-iteration-return/good/two_good_fruit_generator.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
def fruit_generator():
2-
"""The example is simple enough you don't need an explicit return."""
3-
for fruit in ["apple", "banana"]:
4-
yield fruit
5-
6-
7-
def two_fruits_generator(fruits):
8-
"""Catching the StopIteration."""
9-
for fruit in fruits:
10-
try:
11-
yield fruit, next(fruits)
12-
except StopIteration:
13-
print("Sorry there is only one fruit left.")
14-
yield fruit, None
15-
16-
171
def two_good_fruits_generator(fruits):
182
"""A return can be used to end the iterator early, but not a StopIteration."""
193
for fruit in fruits:

0 commit comments

Comments
 (0)