python / python/cpython

Built-in function `range` params discrepancy across versions

Offen
#125,897 10 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

3.12 3.13 3.14 docs
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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:

  1. functions https://docs.python.org/3/library/functions.html
  2. 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:

stdtypes:

source:

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Vergleiche die range-Einträge auf den Dokumentationsseiten functions und stdtypes für die Versionen 3.10 bis 3.13 und verwende die verknüpften rangeobject.c-Quellen, um das Aufrufverhalten zu überprüfen. Prüfe die verknüpften PRs gh-125945, gh-137652 und gh-137653; die Arbeit ist abgeschlossen, wenn die Dokumentation nicht mehr angibt, dass step als Schlüsselwortargument akzeptiert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.