Repository navigation
Built-in function range params discrepancy across versions #125897
Description
Activity
- changed the title
[-]Built-in function `range` params discrepancy[/-][+]Built-in function `range` params discrepancy across versions[/+]on Oct 23, 2024 Yeah, you're right, it should be
class range(start, stop, step=1, /)on the functions page. PR welcome, we're always looking for new contributors :)- added3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes
on Oct 24, 2024 @ZeroIntensity Hmmm... I'm certainly neither an expert nor authority to say what something should (or shouldn't) be; however,
rangeis presented as having an overloaded signature, and I understand why: the function behaves differently depending on the number of args passed, but then I wonder...From the docs:
If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0.
Why is
step=1and notstart=0and how would one writestart=0whenstartisstopin that case?(I'm genuinely asking, by the way. Hopefully I'm not coming off as sarcastic.)
It was
range(start, stop[, step])(like it still is instdtypes) before it was changed in #91485. Specifically #91485 (comment).Back then it was changed to
range(start, stop, step=1, /)in #96579 and soon later torange(start, stop, step=1)in #99476.Yeah, you're right, it should be
class range(start, stop, step=1, /)on the functions page. PR welcome, we're always looking for new contributors :)Shouldn't the
functionsand thestdtypespage be kept in sync, i.e. read exactly the same?Shouldn't the
functionsand thestdtypespage be kept in sync, i.e. read exactly the same?I thought about that, but it doesn't seem like the functions page uses the
[]notation, so I was hesitant to suggest adding it.Reacted by Chris EiblYes, I see. ISTM that after issue #91485 / PR #96579, the
[]notation was no longer favoured in thefunctionspage, but not all occurences/pages were changed (except a few more, see the PRs attached to the issue).Hence the asymmetry.
Just wanted to note and see how others think about it :)
But this is most probably not in the scope of this issue ...
What I specifically wanted to draw attention to: #99476 dropped many trailing
/, e.g.
class:: bool(x=False, /)->class:: bool(x=False)and here we get the sameTypeError: bool() takes no keyword arguments.Now there is Python Documentation Editorial Board decision: https://discuss.python.org/t/editorial-board-decisions/58580
#99476 looks wrong for me.
Reacted by Chris EiblI think that reverting the patch as a whole - is a separate issue. @nedbat, what do you think on this?
But range() issue case shows, that #99476 actually not make the functions page "readable again". Syntax like
range(start, stop, step=1)suggests to user, that at least thestepargument name (in fact, all argument names) is a part of API. And that is wrong.Take look on the tutorial section 4.9. More on Defining Functions. Hardly after reading about default values and keyword arguments people can expect that function declaration like
range(start, stop, step=1)in fact forbid usage with keyword argumentstep.If we wish to keep "readable" syntax, we could actually change argument processing to support keyword arguments. This come with a performance penalty, but not too big (1-3% percent with AC).
- added a commit that references this issue
on Aug 11, 2025 - added a commit that references this issue
on Aug 12, 2025 - added a commit that references this issue
on Sep 11, 2025
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTodo
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:
On the
functionspage, clicking onrangetakes you to https://docs.python.org/3/library/functions.html#func-range . It looks like, as of 3.11, range acceptsstepas a kwarg. This is inconsistent with thestdtypespage which showsstepas 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
stepis not a kwarg.tl;dr - The
functionspage incorrectly states that therangefunction acceptsstepas a kwarg.Linked PRs
range()#125945