From 6eca2c1528d1b6dd7dd61734e0c401ea522ff5f4 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 12 Sep 2023 22:20:51 +0200 Subject: [PATCH] [stop-iteration-return] Use the multiple files template --- .../stop-iteration-return/bad/fruit_generator.py | 4 ++++ .../bad/two_fruit_generator.py | 3 +++ .../{bad.py => bad/two_good_fruit_generator.py} | 11 ----------- .../good/fruit_generator.py | 4 ++++ .../good/two_fruit_generator.py | 8 ++++++++ .../two_good_fruit_generator.py} | 16 ---------------- 6 files changed, 19 insertions(+), 27 deletions(-) create mode 100644 doc/data/messages/s/stop-iteration-return/bad/fruit_generator.py create mode 100644 doc/data/messages/s/stop-iteration-return/bad/two_fruit_generator.py rename doc/data/messages/s/stop-iteration-return/{bad.py => bad/two_good_fruit_generator.py} (54%) create mode 100644 doc/data/messages/s/stop-iteration-return/good/fruit_generator.py create mode 100644 doc/data/messages/s/stop-iteration-return/good/two_fruit_generator.py rename doc/data/messages/s/stop-iteration-return/{good.py => good/two_good_fruit_generator.py} (61%) diff --git a/doc/data/messages/s/stop-iteration-return/bad/fruit_generator.py b/doc/data/messages/s/stop-iteration-return/bad/fruit_generator.py new file mode 100644 index 0000000000..9f1c2321d0 --- /dev/null +++ b/doc/data/messages/s/stop-iteration-return/bad/fruit_generator.py @@ -0,0 +1,4 @@ +def fruit_generator(): + for fruit in ["apple", "banana"]: + yield fruit + raise StopIteration # [stop-iteration-return] diff --git a/doc/data/messages/s/stop-iteration-return/bad/two_fruit_generator.py b/doc/data/messages/s/stop-iteration-return/bad/two_fruit_generator.py new file mode 100644 index 0000000000..d30414bba2 --- /dev/null +++ b/doc/data/messages/s/stop-iteration-return/bad/two_fruit_generator.py @@ -0,0 +1,3 @@ +def two_fruits_generator(fruits): + for fruit in fruits: + yield fruit, next(fruits) # [stop-iteration-return] diff --git a/doc/data/messages/s/stop-iteration-return/bad.py b/doc/data/messages/s/stop-iteration-return/bad/two_good_fruit_generator.py similarity index 54% rename from doc/data/messages/s/stop-iteration-return/bad.py rename to doc/data/messages/s/stop-iteration-return/bad/two_good_fruit_generator.py index d4cd2b35aa..8f45fc48f3 100644 --- a/doc/data/messages/s/stop-iteration-return/bad.py +++ b/doc/data/messages/s/stop-iteration-return/bad/two_good_fruit_generator.py @@ -1,14 +1,3 @@ -def fruit_generator(): - for fruit in ["apple", "banana"]: - yield fruit - raise StopIteration # [stop-iteration-return] - - -def two_fruits_generator(fruits): - for fruit in fruits: - yield fruit, next(fruits) # [stop-iteration-return] - - def two_good_fruits_generator(fruits): for fruit in fruits: if not fruit.is_tasty(): diff --git a/doc/data/messages/s/stop-iteration-return/good/fruit_generator.py b/doc/data/messages/s/stop-iteration-return/good/fruit_generator.py new file mode 100644 index 0000000000..5aaa58f3f2 --- /dev/null +++ b/doc/data/messages/s/stop-iteration-return/good/fruit_generator.py @@ -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 diff --git a/doc/data/messages/s/stop-iteration-return/good/two_fruit_generator.py b/doc/data/messages/s/stop-iteration-return/good/two_fruit_generator.py new file mode 100644 index 0000000000..17d5ff4b55 --- /dev/null +++ b/doc/data/messages/s/stop-iteration-return/good/two_fruit_generator.py @@ -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 diff --git a/doc/data/messages/s/stop-iteration-return/good.py b/doc/data/messages/s/stop-iteration-return/good/two_good_fruit_generator.py similarity index 61% rename from doc/data/messages/s/stop-iteration-return/good.py rename to doc/data/messages/s/stop-iteration-return/good/two_good_fruit_generator.py index eec33d7e42..825580b747 100644 --- a/doc/data/messages/s/stop-iteration-return/good.py +++ b/doc/data/messages/s/stop-iteration-return/good/two_good_fruit_generator.py @@ -1,19 +1,3 @@ -def fruit_generator(): - """The example is simple enough you don't need an explicit return.""" - for fruit in ["apple", "banana"]: - yield fruit - - -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 - - def two_good_fruits_generator(fruits): """A return can be used to end the iterator early, but not a StopIteration.""" for fruit in fruits: