GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-131885: Updates docs to make max and min iterable param positional only by ekohilas · Pull Request #131868 · python/cpython

Conversation

@ekohilas

@ekohilas ekohilas commented Mar 29, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR updates the documentation of max and min to match their implementation like how sorted's implementation matches it's documentation.

Sorted's function definition in the documentation is as follows:

sorted(iterable, /, *, key=None, reverse=False)

When attempted to call with iterable as a keyword argument, the following occurs:

>>> sorted(iterable=[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sorted expected 1 argument, got 0

However, looking at the documentation for max:

max(iterable, *, key=None)

And comparing to their implementation:

>>> max(iterable=[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: max expected at least 1 argument, got 0

The same follows for min


📚 Documentation preview 📚: https://cpython-previews--131868.org.readthedocs.build/

  • Issue: Update function signatures to use * and / as needed #131885

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Mar 29, 2025
@github-project-automation github-project-automation Bot added this to Docs PRs Mar 29, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Mar 29, 2025
@ekohilas
ekohilas marked this pull request as ready for review March 29, 2025 05:26
@ekohilas
ekohilas requested a review from ericsnowcurrently as a code owner March 29, 2025 05:26
@bedevere-app bedevere-app Bot added the awaiting review label Mar 29, 2025
@ekohilas

ekohilas commented Mar 29, 2025

Copy link
Copy Markdown
Contributor Author

Actually, I'm finding more examples of these cases such as map and range. If the above looks good I'll add more commits to include those too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

skirpichev
skirpichev reviewed Mar 29, 2025
View reviewed changes

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm finding more examples of these cases such as map and range. If the above looks good I'll add more commits to include those too.

Previously similar change was reverted: #99476 See also #125945

While devguide suggests now using correct function signatures, I'm not sure we shold push this that way.

We definitely need an issue, e.g. to adjust all signatures on the builtin functions page. We should also consider if we could actually simplify function signatures to avoid '/' and/or '*' syntax. See https://discuss.python.org/t/81003

CC @AA-Turner

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bltinmodule.c Outdated

PyDoc_STRVAR(min_doc,
"min(iterable, *[, default=obj, key=func]) -> value\n\
"min(iterable, /, *[, default=obj, key=func]) -> value\n\

@skirpichev skirpichev Mar 29, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid Python syntax. Same for max().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ekohilas ekohilas Mar 30, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the issue being that the square brackets make it invalid syntax, and that without this change, the documentation would still be wrong.

The reason for change here is to ensure that the web docs align with the code docs, similar to sorted:

cpython/Python/bltinmodule.c

Line 2575 in 5a3f13b

"sorted($module, iterable, /, *, key=None, reverse=False)\n"

Would it be more correct to instead write:

Suggested change
"min(iterable, /, *[, default=obj, key=func]) -> value\n\
"min(iterable, /, *, key=None) -> value\n\
min(iterable, /, *, default, key=None) -> value\n\
min(arg1, arg2, *args, /, *, key=None) -> value\n\

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ekohilas ekohilas Mar 30, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skirpichev Could you please help me understand why -> value should be removed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@skirpichev skirpichev Mar 30, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale is just same as for sphinx docs: it's not a valid syntax (you will get a NameError trying to parse such signature with inspect.signature()).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Mar 30, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the issue being that the square brackets make it invalid syntax, and that without this change, the documentation would still be wrong.

Actually, it's a valid Sphinx syntax. It's the "legacy" way of writing signatures. Many built-ins are written that way. As for ->, I think it was meant for "readability" even if it's unparsable. I would personally leave this untouched in this PR (namely, only add positional-only marker but leave out the ->). In a follow-up, we could clean-up the way "invalid" syntaxes, but this is something different than adding the markers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ekohilas reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ekohilas
ekohilas commented Mar 30, 2025
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

ekohilas
ekohilas commented Mar 30, 2025
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ekohilas

ekohilas commented Mar 30, 2025

Copy link
Copy Markdown
Contributor Author

Actually, I'm finding more examples of these cases such as map and range. If the above looks good I'll add more commits to include those too.

Previously similar change was reverted: #99476 See also #125945

Thanks for these references!

While devguide suggests now using correct function signatures, I'm not sure we shold push this that way.

We definitely need an issue, e.g. to adjust all signatures on the builtin functions page. We should also consider if we could actually simplify function signatures to avoid '/' and/or '*' syntax. See https://discuss.python.org/t/81003

Thank you for linking this read!

I too would like to see simplifying these built-in function signatures, and have functions like range allow for keyword arguments.

As I understand it, doing so would be a one day door that would require additional thought and decisions, as if it went through and started to be used, it would no longer be backwards compatible.

Until then, this seems like the next best step. It's what the Editorial board has agreed on, it brings consistency, and reverting these changes in the future if and when they are simplified would be easy.

As it stands, without these changes:

  • The documentation is inconsistent and causes confusion. e.g.
    • For max, * is used to highlight how the function works, but / isn't, even though it behaves like it is.
    • There is no reference in the docs to specify that max doesn't allow some arguments as keyword.
  • It's difficult for users to understand what the correct usage is, or how to re-create these functions themselves. If a user copies this function definition to do so, it would not match the real definition.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

skirpichev
skirpichev reviewed Mar 30, 2025
View reviewed changes
Comment thread Python/bltinmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ekohilas

ekohilas commented Mar 30, 2025

Copy link
Copy Markdown
Contributor Author

Created issue: #131885

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev skirpichev changed the title Updates docs to make max and min iterable param positional only gh-131885: Updates docs to make max and min iterable param positional only Mar 30, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Mar 30, 2025
Update function signatures to use * and / as needed #131885
Open
4 of 5 tasks
@picnixz

picnixz commented Mar 30, 2025

Copy link
Copy Markdown
Member

While devguide suggests now using correct function signatures, I'm not sure we shold push this that way.

Personally, I read this is as requirement and not a suggestion. Namely,

If a function accepts positional-only or keyword-only arguments, include the slash and the star in the signature as appropriate:

Here, the include is an imperative form and not a recommendation IMO. In addition, the rationale is (emphasis mine)

Although the syntax is terse, it is precise about the allowable ways to call the function and is taken from Python itself.

So I think it's fine to accept those changes. The reversal of previous changes was mostly done because it was incorrect, albeit eval() could have used a positional-only at the end.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Mar 30, 2025
View reviewed changes
Comment thread Python/bltinmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bltinmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented Mar 30, 2025

Copy link
Copy Markdown
Member

So I think it's fine to accept those changes.

Probably, yes. But rather than mechanically accept "complex" signatures - we should revisit on case-by-case basis if we could simplify them. E.g. support bool(x) instead of bool(x, /).

The reversal of previous changes was mostly done because it was incorrect

@picnixz, are you about #99476? Reversion was argued not by correctness: #98340

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Mar 30, 2025

Copy link
Copy Markdown
Member

Wait, were you talking about #100547 or another reversal?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Mar 30, 2025

Copy link
Copy Markdown
Member

Ah no I see. Ok you were talking about another PR. My bad. Well, the EB decision is quite recent and the reversal was done before that decision so I think it doesn't apply here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AA-Turner

AA-Turner commented Mar 30, 2025

Copy link
Copy Markdown
Member

Probably, yes. But rather than mechanically accept "complex" signatures - we should revisit on case-by-case basis if we could simplify them. E.g. support bool(x) instead of bool(x, /).

For this reason, I'm not sure the tracking issue is helpful -- it will encourage people to create many PRs to 'fix' the issue, when it is not just a mechanical transformation at hand.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Mar 30, 2025

Copy link
Copy Markdown
Member

I'm not sure the tracking issue is helpful

This is the reason why I didn't add the "easy" label. But tracking is fine I think. I can add a warning note to say that it's not an easy one as the transformation is not just mechanical

AA-Turner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented Mar 30, 2025

Copy link
Copy Markdown
Member

I'm not sure the tracking issue is helpful -- it will encourage people to create many PRs to 'fix' the issue, when it is not just a mechanical transformation at hand.

Someone could comment on issue to clarify it further.

picnixz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Mar 30, 2025

Copy link
Copy Markdown
Member

I've added a red caution box, hopefully it will be seen

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AA-Turner
AA-Turner requested changes Mar 30, 2025
View reviewed changes

@AA-Turner AA-Turner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid mixing C-style [,optional-arg] with the / etc markers.

I think we should also not conflate changes to the documentation, which support a wider range of syntax, with changes to function signatures in docstrings, which are interpreted by pydoc, help(), etc. See Raymond's Discourse post on improving support for signatures, and Serhiy's draft work on multi-signature support for inspect.

For now, please revert the changes to bltinmodule.c, and we can start with iterative improvements to the rST documentation.

A

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ekohilas reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot removed the awaiting review label Mar 30, 2025
@bedevere-app

bedevere-app Bot commented Mar 30, 2025

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting changes label Mar 30, 2025
@AA-Turner
AA-Turner removed the request for review from ericsnowcurrently March 30, 2025 17:19
ekohilas and others added 4 commits April 12, 2025 10:51
@ekohilas
Update functions.rst
c48ff1b
@ekohilas
Update bltinmodule.c for min and max
df21826
@skirpichev @ekohilas
Apply suggestions from code review
e3399a2
Co-authored-by: Evan Kohilas <[email protected]>
@ekohilas
revert
2e26c23
@ekohilas
ekohilas force-pushed the patch-1 branch from 8771da9 to 2e26c23 Compare April 12, 2025 00:51
@skirpichev

skirpichev commented Apr 12, 2025

Copy link
Copy Markdown
Member

@ekohilas, please avoid force-pushing to the PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ekohilas

ekohilas commented Apr 12, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@ekohilas, please avoid force-pushing to the PR.

Ah sorry I'm clicking the rebase button via GitHub.

Are there guidelines on why I should avoid force pushing in the cpython repo?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented Apr 12, 2025

Copy link
Copy Markdown
Member

Sure, they listed in the devguide: https://devguide.python.org/getting-started/pull-request-lifecycle/#id2

ekohilas reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev skirpichev mentioned this pull request Aug 10, 2025
gh-137609: Update signatures of builtins in the documentation #137610
Merged
terryjreedy
terryjreedy approved these changes Aug 11, 2025
View reviewed changes

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #137610, Serhiy proposes to put /s everywhere they belong, and I strongly support this. HIs PR #137609 includes the 2 additions here, so he also approves them. I think that this should be merged first so that OP gets the proper credit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels Aug 11, 2025
@terryjreedy

terryjreedy commented Aug 11, 2025

Copy link
Copy Markdown
Member

@AA-Turner You requested removal of changes from the .c module, and this was done. Anything else? or dismiss change?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AA-Turner AA-Turner added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Aug 11, 2025
AA-Turner
AA-Turner approved these changes Aug 11, 2025
View reviewed changes
@AA-Turner
AA-Turner merged commit dd079db into python:main Aug 11, 2025
@miss-islington-app

miss-islington-app Bot commented Aug 11, 2025

Copy link
Copy Markdown

Thanks @ekohilas for the PR, and @AA-Turner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Aug 11, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Aug 11, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 11, 2025
@ekohilas @miss-islington
pythongh-131885: Use positional-only markers for max() and ``min(…
de6a0cd
…)`` (pythonGH-131868)

(cherry picked from commit dd079db)

Co-authored-by: Evan Kohilas <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 11, 2025
@ekohilas @miss-islington
pythongh-131885: Use positional-only markers for max() and ``min(…
b38e702
…)`` (pythonGH-131868)

(cherry picked from commit dd079db)

Co-authored-by: Evan Kohilas <[email protected]>
@bedevere-app

bedevere-app Bot commented Aug 11, 2025

Copy link
Copy Markdown

GH-137656 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Aug 11, 2025
@bedevere-app

bedevere-app Bot commented Aug 11, 2025

Copy link
Copy Markdown

GH-137657 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Aug 11, 2025
AA-Turner pushed a commit that referenced this pull request Aug 11, 2025
@miss-islington @ekohilas
[3.13] gh-131885: Use positional-only markers for max() and ``min…
c1e1c88
…()`` (GH-131868) (#137657)

Co-authored-by: Evan Kohilas <[email protected]>
maurycy added a commit to maurycy/cpython that referenced this pull request Aug 12, 2025
@maurycy
Merge branch 'main' into csv-sniffer-counter-set
11c891d
* main:
  pythongh-137288: Update 3.14 magic numbers (pythonGH-137665)
  pythongh-135228: When @DataClass(slots=True) replaces a dataclass, make the original class collectible (take 2) (pythonGH-137047)
  pythongh-126008: Improve docstrings for Tkinter cget and configure methods (pythonGH-133303)
  pythongh-131885: Use positional-only markers for ``max()`` and ``min()`` (python#131868)
  pythonGH-137426: Remove code deprecation of `importlib.abc.ResourceLoader` (pythonGH-137567)
  pythongh-125897: Mark range function parameters as positional only (python#125945)
  pythongh-137400: Fix a crash when disabling profiling across all threads (pythongh-137471)
  pythongh-115766: Fix IPv4Interface.is_unspecified (pythonGH-137326)
  pythongh-128813: cleanup C-API docs for PyComplexObject (pythonGH-137579)
  pythongh-135953: Profile a module or script with sampling profiler (python#136777)
  Fix documentation of hash in PyHash_FuncDef (python#137595)
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@ekohilas @Agent-Hellboy
pythongh-131885: Use positional-only markers for max() and ``min(…
7da761a
…)`` (python#131868)
AA-Turner pushed a commit that referenced this pull request Oct 7, 2025
@miss-islington @ekohilas
[3.14] gh-131885: Use positional-only markers for max() and ``min…
94f57ac
…()`` (GH-131868) (#137656)

gh-131885: Use positional-only markers for ``max()`` and ``min()`` (GH-131868)
(cherry picked from commit dd079db)

Co-authored-by: Evan Kohilas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@skirpichev skirpichev skirpichev left review comments
@picnixz picnixz picnixz left review comments
@AA-Turner AA-Turner AA-Turner approved these changes
@terryjreedy terryjreedy terryjreedy approved these changes
+1 more reviewer
@XuehaiPan XuehaiPan XuehaiPan left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@ekohilas @picnixz @skirpichev @AA-Turner @terryjreedy @XuehaiPan
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.