Skip to content

gh-65557: Clarify 'only evaluated once' in augmented assignment docs#153264

Open
7SH7 wants to merge 1 commit into
python:mainfrom
7SH7:gh-65557-augmented-assignment-doc
Open

gh-65557: Clarify 'only evaluated once' in augmented assignment docs#153264
7SH7 wants to merge 1 commit into
python:mainfrom
7SH7:gh-65557-augmented-assignment-doc

Conversation

@7SH7

@7SH7 7SH7 commented Jul 7, 2026

Copy link
Copy Markdown

The reference manual currently says that the target of an augmented
assignment "is only evaluated once". As discussed in the issue, this is
imprecise: for a target like y[k], the subexpressions y and k
are evaluated only once, but the subscription itself may be performed
twice — once to fetch the old value and once to store the result.

This can be observed directly:

>>> def ob():  print('ob evaluated');  return d
>>> def key(): print('key evaluated'); return 0
>>> d = [[]]
>>> ob()[key()] += [1]   # ob and key run once, but d[0] is read and then written
ob evaluated
key evaluated

This PR rewords both sentences to say that the subexpressions of the
target are only evaluated once, and adds the y[k] example, following
the wording suggested by @terryjreedy in the issue.

Fixes gh-65557

@7SH7 7SH7 requested review from AA-Turner and willingc as code owners July 7, 2026 13:39
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Jul 7, 2026
@python-cla-bot

python-cla-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33479334 | 📁 Comparing aab8867 against main (2cd5b79)

  🔍 Preview build  

1 file changed
± reference/simple_stmts.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Augmented assignment doc: clarify 'only evaluated once'

1 participant