Built-in function `range` params discrepancy across versions
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
I'm sorry if this has already been reported. I'm sure it's very low on any list of priorities but it should be an easy one.
I noticed that when doing a Google search for "python built in functions" I am presented with two official results:
- functions https://docs.python.org/3/library/functions.html
- stdtypes https://docs.python.org/3/library/stdtypes.html
On the functions page, clicking on range takes you to https://docs.python.org/3/library/functions.html#func-range . It looks like, as of 3.11, range accepts step as a kwarg. This is inconsistent with the stdtypes page which shows step as an optional, positional arg through 3.13.
functions:
- 3.10 https://docs.python.org/3.10/library/functions.html#func-range
- 3.11 https://docs.python.org/3.11/library/functions.html#func-range
- 3.12 https://docs.python.org/3.12/library/functions.html#func-range
- 3.13 https://docs.python.org/3.13/library/functions.html#func-range
stdtypes:
- 3.10 https://docs.python.org/3.10/library/stdtypes.html#range
- 3.11 https://docs.python.org/3.11/library/stdtypes.html#range
- 3.12 https://docs.python.org/3.12/library/stdtypes.html#range
- 3.13 https://docs.python.org/3.13/library/stdtypes.html#range
source:
- 3.10 https://github.com/python/cpython/blob/3.10/Objects/rangeobject.c#L159
- 3.11 https://github.com/python/cpython/blob/3.11/Objects/rangeobject.c#L157
- 3.12 https://github.com/python/cpython/blob/3.12/Objects/rangeobject.c#L156
- 3.13 https://github.com/python/cpython/blob/3.13/Objects/rangeobject.c#L158
I didn't see any mention of this change in What’s New In Python 3.11 and it surprised me that a built-in would be changed in such a way.
I pulled a 3.11 docker image and it would seem step is not a kwarg.
docker run -it --rm python:3.11
Python 3.11.10 (main, Oct 19 2024, 04:02:01) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> range(1, 1, step=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: range() takes no keyword arguments
tl;dr - The functions page incorrectly states that the range function accepts step as a kwarg.
Linked PRs
- gh-125945
- gh-137652
- gh-137653
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
比较 3.10 至 3.13 版本的 functions 和 stdtypes 文档页面中的 range 条目,使用链接的 rangeobject.c 源码验证调用行为。审阅链接的 PR gh-125945、gh-137652 和 gh-137653;当文档不再声称 step 可作为关键字参数接受时,工作即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100