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-137609: Update signatures of builtins in the documentation by serhiy-storchaka · Pull Request #137610 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 10, 2025 •
edited by github-actions Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Show signatures that match the actual signatures or future multisignatures for all functions, classes and methods in the "builtins" module.

  • Issue: Update signatures of builtins in the documentation #137609

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

Sorry, something went wrong.

Uh oh!

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

terryjreedy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@serhiy-storchaka
pythongh-137609: Update signatures of builtins in the documentation
5f13e6f
Show signatures that match the actual signatures or future multisignatures
for all functions, classes and methods in the "builtins" module.
@serhiy-storchaka serhiy-storchaka added docs Documentation in the Doc dir skip news needs backport to 3.13 only security fixes labels Aug 10, 2025
@github-project-automation github-project-automation Bot added this to Docs PRs Aug 10, 2025
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label Aug 10, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Aug 10, 2025
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 10, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Aug 10, 2025
Update signatures of builtins in the documentation #137609
Closed
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Aug 10, 2025
@serhiy-storchaka
pythongh-137609: Change names of some positional-only parameters in b…
aeda212
…uiltins

This is to pair with pythonGH-137610.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Aug 10, 2025
@serhiy-storchaka
pythongh-137609: Change names of some positional-only parameters in b…
d7d3981
…uiltins

This is to pair with pythonGH-137610.
@serhiy-storchaka serhiy-storchaka mentioned this pull request Aug 10, 2025
gh-137609: Change names of some positional-only parameters in builtins #137611
Merged
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner August 10, 2025 14:11
@serhiy-storchaka

serhiy-storchaka commented Aug 10, 2025

Copy link
Copy Markdown
Member Author

See also #137611.

All reactions

Sorry, something went wrong.

Uh oh!

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

skirpichev
skirpichev reviewed Aug 10, 2025
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

terryjreedy
terryjreedy previously requested changes Aug 10, 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.

I approve of the issue, the addition of /s, the renamings, and most of the details. The main question for me is relative positioning of / and *args.

Fewer versus more lines is partly style preference and partly technical accuracy, and the signature needed to have an inspect.signature and to write a python version of the same or similar function, versus ease of understanding how to call the function. Are "future multisignatures" a real possibility?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/functions.rst Outdated
Comment on lines 185 to 188
.. class:: bytearray()
bytearray(source)
bytearray(source, encoding)
bytearray(source, encoding, errors)

@terryjreedy terryjreedy Aug 10, 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.

I believe only two lines are needed.

Suggested change
.. class:: bytearray()
bytearray(source)
bytearray(source, encoding)
bytearray(source, encoding, errors)
.. class:: bytearray(source=b'')
bytearray(source, encoding, errors='strict')

See also #137100, which is also about the text that follows.

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka Aug 10, 2025

Copy link
Copy Markdown
Member 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.

Some descriptions have separate signature for no argument, others merge it with a signature with one argument. See for example dict which could be written as dict(mapping_or_iterable=(), **kwargs), but is written as three semantically different signatures. I tried to be more consistent and chose the former variant. But I have no such strong preference.

Sorry, something went wrong.

Uh oh!

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

All reactions

@terryjreedy terryjreedy Aug 11, 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.

I prefer fewer lines, and approve of the changes.

Sorry, something went wrong.

Uh oh!

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

All reactions

@AA-Turner AA-Turner Aug 11, 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.

I'm not sure I agree here, source=b'' makes it less clear to me that source also accepts e.g. iterables of integers, buffer-protocol, etc. I would suggest:

.. class:: bytearray()
           bytearray(source, /)
           bytearray(source, /, encoding, errors='strict')

Note I have suggested to annotate 'source' as positional-only -- I think this makes more sense to users than writing e.g. bytearray(source=my_numpy_array). My IDE & type-checkers also indicates that source=... is an error, as it is annotated as positional-only in typeshed.

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 Doc/library/functions.rst Resolved

Uh oh!

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

Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting core review label Aug 10, 2025
@bedevere-app

bedevere-app Bot commented Aug 10, 2025

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

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 Aug 10, 2025
StanFromIreland
StanFromIreland reviewed Aug 10, 2025
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

@serhiy-storchaka
Use less signatures and more default values.
72157aa
serhiy-storchaka
serhiy-storchaka commented Aug 10, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member 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 have made the requested changes; please review again.

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 Doc/library/functions.rst Outdated
Comment on lines 185 to 188
.. class:: bytearray()
bytearray(source)
bytearray(source, encoding)
bytearray(source, encoding, errors)

@serhiy-storchaka serhiy-storchaka Aug 10, 2025

Copy link
Copy Markdown
Member 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.

Some descriptions have separate signature for no argument, others merge it with a signature with one argument. See for example dict which could be written as dict(mapping_or_iterable=(), **kwargs), but is written as three semantically different signatures. I tried to be more consistent and chose the former variant. But I have no such strong preference.

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 Doc/library/functions.rst Resolved

Uh oh!

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

Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

terryjreedy
terryjreedy reviewed Aug 11, 2025
View reviewed changes
Comment thread Doc/library/functions.rst Resolved

Uh oh!

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

This was referenced Aug 11, 2025
gh-125897: Use positional-only parameter indicators for range() #125945
Merged
gh-131885: Updates docs to make max and min iterable param positional only #131868
Merged
AA-Turner and others added 2 commits August 12, 2025 00:30
@AA-Turner
Merge branch 'main' into docs-builtins-signatures
d08e13f
@AA-Turner @terryjreedy
Update Doc/library/functions.rst
94cc645
Co-authored-by: Terry Jan Reedy <[email protected]>
@terryjreedy
terryjreedy dismissed their stale review August 12, 2025 00:02

Typo fixed.

@bedevere-app bedevere-app Bot added awaiting review and removed awaiting changes labels Aug 12, 2025
serhiy-storchaka added 5 commits August 13, 2025 12:33
@serhiy-storchaka
Rename "bytes" back to "chars".
b159ccd
@serhiy-storchaka
Revert "Rename "bytes" back to "chars"."
c2068d2
This reverts commit b159ccd.
@serhiy-storchaka
Remove outdated explanation of the "chars" name.
c06089f
@serhiy-storchaka
Add missed '/'s.
8b5e802
@serhiy-storchaka
Add a signature for weird str() case.
de15f70
@serhiy-storchaka
serhiy-storchaka force-pushed the docs-builtins-signatures branch from 00556ee to de15f70 Compare August 13, 2025 10:39
JelleZijlstra
JelleZijlstra reviewed Aug 15, 2025
View reviewed changes

@JelleZijlstra JelleZijlstra 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.

Thanks for doing this!

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/functions.rst
.. _func-str:
.. class:: str(object='')
str(object=b'', encoding='utf-8', errors='strict')
.. class:: str(*, encoding='utf-8', errors='strict')

@JelleZijlstra JelleZijlstra Aug 15, 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.

It's technically true that you can pass just the encoding or errors kwargs (like str(encoding='ebcdic')), but it's not practically useful, since you just get an empty string whatever encoding you pass, and I fear it's confusing to users to put this here.

The old docs here feel clearer even if they're not as precise.

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka Aug 15, 2025

Copy link
Copy Markdown
Member 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.

We should be technically correct.

Several years ago I proposed to deprecate this case, but my proposition was rejected. If it is worth to continue supporting this in code, it is worth to document it. Note that values of encoding and errors are ignored:

>>> str(encoding='spam', errors='ham')
''

Sorry, something went wrong.

Uh oh!

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

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

Uh oh!

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

Comment thread Doc/library/functions.rst

.. _func-frozenset:
.. class:: frozenset(iterable=set())
.. class:: frozenset(iterable=(), /)

@JelleZijlstra JelleZijlstra Aug 15, 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.

Either approach could work but I like the way it's in the current PR; it's better to have fewer distinct signatures.

Sorry, something went wrong.

Uh oh!

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

All reactions
serhiy-storchaka and others added 5 commits August 15, 2025 10:11
@serhiy-storchaka @JelleZijlstra
Update Doc/library/stdtypes.rst
150ad5b
Co-authored-by: Jelle Zijlstra <[email protected]>
@serhiy-storchaka
mamoryview.index() has parameter "stop".
402efa9
@serhiy-storchaka
Add signatures for str.maketrans().
61754a3
@serhiy-storchaka
Revert changes for signatures with start/end indices.
816dea7
@serhiy-storchaka
Merge branch 'main' into docs-builtins-signatures
2961fff
@serhiy-storchaka

serhiy-storchaka commented Aug 25, 2025

Copy link
Copy Markdown
Member Author

Reverted changes for signatures with start/end parameters, as this is a separate non-trivial issue (#138134).

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
serhiy-storchaka merged commit 65fb4d1 into python:main Aug 25, 2025
@miss-islington-app

miss-islington-app Bot commented Aug 25, 2025

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

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 25, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Aug 25, 2025
@serhiy-storchaka
serhiy-storchaka deleted the docs-builtins-signatures branch August 25, 2025 12:28
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 25, 2025
@serhiy-storchaka @miss-islington
pythongh-137609: Update signatures of builtins in the documentation (p…
2baa530
…ythonGH-137610)

Show signatures that match the actual signatures or future multisignatures
for all functions, classes and methods in the "builtins" module.
(cherry picked from commit 65fb4d1)

Co-authored-by: Serhiy Storchaka <[email protected]>
@miss-islington-app

miss-islington-app Bot commented Aug 25, 2025

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 65fb4d11a0f3f3e4aea373bd84918e4445cbfe67 3.13
All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented Aug 25, 2025

Copy link
Copy Markdown

GH-138137 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 25, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Aug 25, 2025
@serhiy-storchaka
[3.13] pythongh-137609: Update signatures of builtins in the document…
bb78e24
…ation (pythonGH-137610)

Show signatures that match the actual signatures or future multisignatures
for all functions, classes and methods in the "builtins" module.
(cherry picked from commit 65fb4d1)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app

bedevere-app Bot commented Aug 25, 2025

Copy link
Copy Markdown

GH-138138 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 25, 2025
serhiy-storchaka added a commit that referenced this pull request Aug 25, 2025
@serhiy-storchaka
gh-137609: Change names of some positional-only parameters in builtins (
b8c90e7
GH-137611)

This is for a pair with GH-137610.
serhiy-storchaka added a commit that referenced this pull request Aug 25, 2025
@serhiy-storchaka
[3.13] gh-137609: Update signatures of builtins in the documentation (G…
bad7bc4
…H-137610) (GH-138138)

Show signatures that match the actual signatures or future multisignatures
for all functions, classes and methods in the "builtins" module.
(cherry picked from commit 65fb4d1)
@serhiy-storchaka serhiy-storchaka mentioned this pull request Aug 25, 2025
bytes() and bytearray() should have the default values for errors for string sources #137100
Closed
hugovk pushed a commit that referenced this pull request Aug 27, 2025
@miss-islington @serhiy-storchaka
[3.14] gh-137609: Update signatures of builtins in the documentation (G…
cc38a57
…H-137610) (#138137)

Co-authored-by: Serhiy Storchaka <[email protected]>
kumaraditya303 pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2025
@miss-islington @serhiy-storchaka @kumaraditya303
[3.14] pythongh-137609: Update signatures of builtins in the document…
6ef4fed
…ation (pythonGH-137610) (python#138137)

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

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra left review comments
@skirpichev skirpichev skirpichev left review comments
@AA-Turner AA-Turner AA-Turner left review comments
@StanFromIreland StanFromIreland StanFromIreland left review comments
@terryjreedy terryjreedy terryjreedy approved these changes

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

@serhiy-storchaka @JelleZijlstra @skirpichev @AA-Turner @terryjreedy @StanFromIreland
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.