python / python/cpython

Assignment operator: incorrect wording

未关闭
#98,814 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

docs
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Two quotes from The Python 3.11.0 Language Reference (emphasize is mine):

  • Note: If the object is a class instance and the attribute reference occurs on both sides of the assignment operator
  • Delimiters: The second half of the list, the augmented assignment operators, serve lexically as delimiters, but also perform an operation

As explained at the expression entry term in the glossary, an operator is a syntatical element involved in an expression. An expression has a value. The piece of syntax (a = expr) is not an expression because it cannot be evaluated. And as explained at the same entry, assignment are also statement, not expression.

In the same way there is no del/return operator, it is not correct to invoke an assignment operator, the correct wording being "assignment statement" as used in many places in The Python Language Reference Manual. The only "assignment operator" we can figure out is the walrus operator because (a := expr) has a value.

For consistency, we can observe that assignment symbols (=, +=, etc), contrary to the walrus symbol, are not listed in:

  • the set of tokens considered as operators
  • the operator precedence table.

Thomas Wouters explains in a SO comment :

Assignment is actually not an expression in Python, and = not an operator in the normal sense; operator precedence doesn't apply.

Related reference of interest: = is not an operator

EDIT:

...doesn't exist, since '=' is not an operator in Python (just like it isn't, say, in VB). But, OK, you mean "assignment".

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

检查关于简单语句和词法分析的 Language Reference 链接章节,以及表达式词汇表条目和运算符优先级表。在文档中搜索“assignment operator”的使用,并确定哪些地方应改为“assignment statement”,然后核实术语与周围的参考文本保持一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
documentation
Issue 类型
文档
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。