-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stop-iteration-return] Use the multiple files template
- Loading branch information
1 parent
2f8bbf4
commit 8da684e
Showing
6 changed files
with
19 additions
and
27 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
doc/data/messages/s/stop-iteration-return/bad/fruit_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def fruit_generator(): | ||
for fruit in ["apple", "banana"]: | ||
yield fruit | ||
raise StopIteration # [stop-iteration-return] |
3 changes: 3 additions & 0 deletions
3
doc/data/messages/s/stop-iteration-return/bad/two_fruit_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def two_fruits_generator(fruits): | ||
for fruit in fruits: | ||
yield fruit, next(fruits) # [stop-iteration-return] |
11 changes: 0 additions & 11 deletions
11
...a/messages/s/stop-iteration-return/bad.py → ...on-return/bad/two_good_fruit_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
doc/data/messages/s/stop-iteration-return/good/fruit_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def fruit_generator(): | ||
"""The example is simple enough you don't need an explicit return.""" | ||
for fruit in ["apple", "banana"]: | ||
yield fruit |
8 changes: 8 additions & 0 deletions
8
doc/data/messages/s/stop-iteration-return/good/two_fruit_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def two_fruits_generator(fruits): | ||
"""Catching the StopIteration.""" | ||
for fruit in fruits: | ||
try: | ||
yield fruit, next(fruits) | ||
except StopIteration: | ||
print("Sorry there is only one fruit left.") | ||
yield fruit, None |
16 changes: 0 additions & 16 deletions
16
.../messages/s/stop-iteration-return/good.py → ...n-return/good/two_good_fruit_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters