aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Doc/reference/expressions.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/reference/expressions.rst')
-rw-r--r--Doc/reference/expressions.rst18
1 files changed, 10 insertions, 8 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 8837344e5dd..24544a055c3 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -134,8 +134,7 @@ Literals
Python supports string and bytes literals and various numeric literals:
.. productionlist:: python-grammar
- literal: `stringliteral` | `bytesliteral`
- : | `integer` | `floatnumber` | `imagnumber`
+ literal: `stringliteral` | `bytesliteral` | `NUMBER`
Evaluation of a literal yields an object of the given type (string, bytes,
integer, floating-point number, complex number) with the given value. The value
@@ -406,8 +405,9 @@ brackets or curly braces.
Variables used in the generator expression are evaluated lazily when the
:meth:`~generator.__next__` method is called for the generator object (in the same
fashion as normal generators). However, the iterable expression in the
-leftmost :keyword:`!for` clause is immediately evaluated, so that an error
-produced by it will be emitted at the point where the generator expression
+leftmost :keyword:`!for` clause is immediately evaluated, and the
+:term:`iterator` is immediately created for that iterable, so that an error
+produced while creating the iterator will be emitted at the point where the generator expression
is defined, rather than at the point where the first value is retrieved.
Subsequent :keyword:`!for` clauses and any filter condition in the leftmost
:keyword:`!for` clause cannot be evaluated in the enclosing scope as they may
@@ -625,8 +625,10 @@ is already executing raises a :exc:`ValueError` exception.
.. method:: generator.close()
- Raises a :exc:`GeneratorExit` at the point where the generator function was
- paused. If the generator function catches the exception and returns a
+ Raises a :exc:`GeneratorExit` exception at the point where the generator
+ function was paused (equivalent to calling ``throw(GeneratorExit)``).
+ The exception is raised by the yield expression where the generator was paused.
+ If the generator function catches the exception and returns a
value, this value is returned from :meth:`close`. If the generator function
is already closed, or raises :exc:`GeneratorExit` (by not catching the
exception), :meth:`close` returns :const:`None`. If the generator yields a
@@ -1023,7 +1025,7 @@ series of :term:`arguments <argument>`:
: ["," `keywords_arguments`]
: | `starred_and_keywords` ["," `keywords_arguments`]
: | `keywords_arguments`
- positional_arguments: positional_item ("," positional_item)*
+ positional_arguments: `positional_item` ("," `positional_item`)*
positional_item: `assignment_expression` | "*" `expression`
starred_and_keywords: ("*" `expression` | `keyword_item`)
: ("," "*" `expression` | "," `keyword_item`)*
@@ -1928,7 +1930,7 @@ Expression lists
single: , (comma); expression list
.. productionlist:: python-grammar
- starred_expression: ["*"] `or_expr`
+ starred_expression: "*" `or_expr` | `expression`
flexible_expression: `assignment_expression` | `starred_expression`
flexible_expression_list: `flexible_expression` ("," `flexible_expression`)* [","]
starred_expression_list: `starred_expression` ("," `starred_expression`)* [","]