Skip to content

bpo-39868: Update Language Reference for PEP 572. #18793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ The :keyword:`!if` statement
The :keyword:`if` statement is used for conditional execution:

.. productionlist::
if_stmt: "if" `expression` ":" `suite`
: ("elif" `expression` ":" `suite`)*
if_stmt: "if" `assignment_expression` ":" `suite`
: ("elif" `assignment_expression` ":" `suite`)*
: ["else" ":" `suite`]

It selects exactly one of the suites by evaluating the expressions one by one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think "expression" here needs updating too? It becomes a bit ugly that way, and in context it doesn't seem ambiguous.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I thought more about it and I don't think it needs updating, so I'll land now.)

Expand All @@ -116,7 +116,7 @@ The :keyword:`while` statement is used for repeated execution as long as an
expression is true:

.. productionlist::
while_stmt: "while" `expression` ":" `suite`
while_stmt: "while" `assignment_expression` ":" `suite`
: ["else" ":" `suite`]

This repeatedly tests the expression and, if it is true, executes the first
Expand Down
18 changes: 15 additions & 3 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ called "displays", each of them in two flavors:
Common syntax elements for comprehensions are:

.. productionlist::
comprehension: `expression` `comp_for`
comprehension: `assignment_expression` `comp_for`
comp_for: ["async"] "for" `target_list` "in" `or_test` [`comp_iter`]
comp_iter: `comp_for` | `comp_if`
comp_if: "if" `expression_nocond` [`comp_iter`]
Expand Down Expand Up @@ -911,7 +911,8 @@ series of :term:`arguments <argument>`:
: ["," `keywords_arguments`]
: | `starred_and_keywords` ["," `keywords_arguments`]
: | `keywords_arguments`
positional_arguments: ["*"] `expression` ("," ["*"] `expression`)*
positional_arguments: positional_item ("," positional_item)*
positional_item: `assignment_expression` | "*" `expression`
starred_and_keywords: ("*" `expression` | `keyword_item`)
: ("," "*" `expression` | "," `keyword_item`)*
keywords_arguments: (`keyword_item` | "**" `expression`)
Expand Down Expand Up @@ -1642,6 +1643,17 @@ returns a boolean value regardless of the type of its argument
(for example, ``not 'foo'`` produces ``False`` rather than ``''``.)


Assignment expressions
======================

.. productionlist::
assignment_expression: [`identifier` ":="] `expression`

.. TODO: BPO-39868

See :pep:`572` for more details about assignment expressions.


.. _if_expr:

Conditional expressions
Expand Down Expand Up @@ -1711,7 +1723,7 @@ Expression lists
expression_list: `expression` ("," `expression`)* [","]
starred_list: `starred_item` ("," `starred_item`)* [","]
starred_expression: `expression` | (`starred_item` ",")* [`starred_item`]
starred_item: `expression` | "*" `or_expr`
starred_item: `assignment_expression` | "*" `or_expr`

.. index:: object: tuple

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated the Language Reference for :pep:`572`.