Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-137609: Update signatures of builtins in the documentation#137610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-137609: Update signatures of builtins in the documentation #137610
Uh oh!
There was an error while loading. Please reload this page.
Conversation
serhiy-storchaka commented Aug 10, 2025 • edited by github-actions bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by github-actions bot
Uh oh!
There was an error while loading. Please reload this page.
Show signatures that match the actual signatures or future multisignatures for all functions, classes and methods in the "builtins" module.
…uiltins This is to pair with pythonGH-137610.
…uiltins This is to pair with pythonGH-137610.
serhiy-storchaka commented Aug 10, 2025
See also #137611. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
terryjreedy left a comment
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?
Doc/library/functions.rst Outdated
| .. class:: bytearray() | ||
| bytearray(source) | ||
| bytearray(source, encoding) | ||
| bytearray(source, encoding, errors) |
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.
| .. 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.
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.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When you're done making the requested changes, leave the comment: |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
serhiy-storchaka left a comment
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.
Uh oh!
There was an error while loading. Please reload this page.
Doc/library/functions.rst Outdated
| .. class:: bytearray() | ||
| bytearray(source) | ||
| bytearray(source, encoding) | ||
| bytearray(source, encoding, errors) |
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
00556ee to de15f70Compare
JelleZijlstra left a comment
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!
| .. _func-str: | ||
| .. class:: str(object='') | ||
| str(object=b'', encoding='utf-8', errors='strict') | ||
| .. class:: str(*, encoding='utf-8', errors='strict') |
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.
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') ''Uh oh!
There was an error while loading. Please reload this page.
| .. _func-frozenset: | ||
| .. class:: frozenset(iterable=set()) | ||
| .. class:: frozenset(iterable=(), /) |
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.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
serhiy-storchaka commented Aug 25, 2025
Reverted changes for signatures with start/end parameters, as this is a separate non-trivial issue (#138134). |
65fb4d1 into python:mainUh oh!
There was an error while loading. Please reload this page.
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…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 <storchaka@gmail.com>
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
GH-138137 is a backport of this pull request to the 3.14 branch. |
…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 <storchaka@gmail.com>
GH-138138 is a backport of this pull request to the 3.13 branch. |
…ation (pythonGH-137610) (python#138137) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Show signatures that match the actual signatures or future multisignatures for all functions, classes and methods in the "builtins" module.
📚 Documentation preview 📚: https://cpython-previews--137610.org.readthedocs.build/