From 2e92aad99200e344c10b1c10f64d4e8ad83ca74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dankiewicz?= Date: Fri, 10 Dec 2021 12:02:01 +0100 Subject: [PATCH 1/6] Remove duplicated sentence from for statement docs --- Doc/reference/compound_stmts.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index cf8ad1787b2915..c3c8b56e2ee025 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -158,13 +158,13 @@ The :keyword:`for` statement is used to iterate over the elements of a sequence : ["else" ":" `suite`] The expression list is evaluated once; it should yield an iterable object. An -iterator is created for the result of the ``expression_list``. The suite is -then executed once for each item provided by the iterator, in the order returned -by the iterator. Each item in turn is assigned to the target list using the -standard rules for assignments (see :ref:`assignment`), and then the suite is -executed. When the items are exhausted (which is immediately when the sequence -is empty or an iterator raises a :exc:`StopIteration` exception), the suite in -the :keyword:`!else` clause, if present, is executed, and the loop terminates. +iterator is created for the result of the ``expression_list``. First item +provided by the iterator is then assigned to the target list using the standard +rules for assignments (see :ref:`assignment`), and the suite is executed - this +repeats for each item provided by the iterator. When the items are exhausted +(which is immediately when the sequence is empty or an iterator raises +a :exc:`StopIteration` exception), the suite in the :keyword:`!else` clause, +if present, is executed, and the loop terminates. .. index:: statement: break From 8b5eb998ae68b4a1606de84598d335e81a016fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dankiewicz?= Date: Mon, 3 Jan 2022 18:51:11 +0100 Subject: [PATCH 2/6] Add news entry --- .../next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst diff --git a/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst b/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst new file mode 100644 index 00000000000000..7d7f2f52f7939a --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst @@ -0,0 +1 @@ +Removed duplicated sentence from ``for`` statement docs. From 8c6856b574a9615b132a7de6f2155e1708b5e3f9 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 2 Apr 2022 17:48:11 -0400 Subject: [PATCH 3/6] Update 2022-01-03-18-50-39.bpo-46033.7WeF0f.rst --- .../next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst b/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst index 7d7f2f52f7939a..a484def239d8b7 100644 --- a/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst +++ b/Misc/NEWS.d/next/Documentation/2022-01-03-18-50-39.bpo-46033.7WeF0f.rst @@ -1 +1 @@ -Removed duplicated sentence from ``for`` statement docs. +Clarify ``for`` statement execution in its doc. From 46037d17ec520768824bf2cc9a5f5f2fcc3e2512 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 2 Apr 2022 18:22:11 -0400 Subject: [PATCH 4/6] Update Doc/reference/compound_stmts.rst Co-authored-by: Jelle Zijlstra --- Doc/reference/compound_stmts.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 703bf3702585fd..8ed592e7e65b75 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -157,7 +157,7 @@ The :keyword:`for` statement is used to iterate over the elements of a sequence for_stmt: "for" `target_list` "in" `starred_list` ":" `suite` : ["else" ":" `suite`] -The starred list expression is evaluated once; it should yield an iterable object. +The ``starred_list`` expression is evaluated once; it should yield an iterable object. If the expression is a sequence, it can contain starred elements (``*x, *y``) that will be unpacked, as when constructing a ``tuple`` or ``list`` literal. An iterator is created for the resulting iterable. The first item provided From 0fd36f886d0df276ab46d30a48c08b116ad5ddcf Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 2 Apr 2022 18:32:08 -0400 Subject: [PATCH 5/6] Update Doc/reference/compound_stmts.rst Co-authored-by: Jelle Zijlstra --- Doc/reference/compound_stmts.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 8ed592e7e65b75..842c543958842d 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -163,9 +163,8 @@ that will be unpacked, as when constructing a ``tuple`` or ``list`` literal. An iterator is created for the resulting iterable. The first item provided by the iterator is then assigned to the target list using the standard rules for assignments (see :ref:`assignment`), and the suite is executed - this -repeats for each item provided by the iterator. When the items are exhausted -(which is immediately when the sequence is empty or an iterator raises -a :exc:`StopIteration` exception), the suite in the :keyword:`!else` clause, +repeats for each item provided by the iterator. When the iterator is exhausted, +the suite in the :keyword:`!else` clause, if present, is executed, and the loop terminates. .. index:: From e2742b0a922e47cb554fe1a52d3f03c0d111f480 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sat, 2 Apr 2022 20:22:04 -0400 Subject: [PATCH 6/6] Incorporate remaining suggestions. --- Doc/reference/compound_stmts.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 842c543958842d..688407195f05dd 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -157,12 +157,11 @@ The :keyword:`for` statement is used to iterate over the elements of a sequence for_stmt: "for" `target_list` "in" `starred_list` ":" `suite` : ["else" ":" `suite`] -The ``starred_list`` expression is evaluated once; it should yield an iterable object. -If the expression is a sequence, it can contain starred elements (``*x, *y``) -that will be unpacked, as when constructing a ``tuple`` or ``list`` literal. -An iterator is created for the resulting iterable. The first item provided +The ``starred_list`` expression is evaluated once; it should yield an +:term:`iterable` object. An :term:`iterator` is created for that iterable. +The first item provided by the iterator is then assigned to the target list using the standard -rules for assignments (see :ref:`assignment`), and the suite is executed - this +rules for assignments (see :ref:`assignment`), and the suite is executed. This repeats for each item provided by the iterator. When the iterator is exhausted, the suite in the :keyword:`!else` clause, if present, is executed, and the loop terminates.