python / python/cpython

`f(kw=a, *b)` with keyword argument before star arguments isn’t evaluated left-to-right

未关闭
#100,549 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

def f(a, kw):
    pass

f(kw=print(1), *[print(2)])

In Python 3.4.10 and earlier, this prints 1 then 2, but in Python 3.5.0 and later, this prints 2 then 1.

This seems like a bug of some kind. Given that ast.parse() doesn’t distinguish between f(kw=a, *b) and f(*b, kw=a), perhaps the bug is that a keyword argument is allowed before star arguments at all—we already disallow f(kw=a, b), f(**a, b), and f(**a, *b).

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先在受影响的 Python 版本上复现所提供的 f(kw=print(1), *[print(2)]) 示例,然后跟踪 CPython 如何解析和求值包含关键字参数和星号参数的调用。当行为得到一致修正,或者在所选解决方案是拒绝无效参数顺序的情况下拒绝该顺序时,即视为完成;该 issue 未指定源文件或测试。

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

评估

技术栈
python
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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