-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
base: main
Are you sure you want to change the base?
gh-137609: Update signatures of builtins in the documentation #137610
Conversation
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.
See also #137611. |
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?
When you're done making the requested changes, leave the 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.
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
||
As :func:`repr`, return a string containing a printable representation of an | ||
object, but escape the non-ASCII characters in the string returned by | ||
:func:`repr` using ``\x``, ``\u``, or ``\U`` escapes. This generates a string | ||
similar to that returned by :func:`repr` in Python 2. | ||
|
||
|
||
.. function:: bin(x) | ||
.. function:: bin(integer, /) |
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.
'integer' could be too close to int
for confusion
.. function:: bin(integer, /) | |
.. function:: bin(num, /) |
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 initially used number
(it is used in the builtin signature), but changed it to integer, since only int
and objects implementing __index__
are supported. In many other parts of the documentation "integer" means "int
or objects implementing __index__
".
Doc/library/functions.rst
Outdated
@@ -244,7 +242,7 @@ are always available. They are listed here in alphabetical order. | |||
in Python 3.2. | |||
|
|||
|
|||
.. function:: chr(i) | |||
.. function:: chr(i, /) |
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.
.. function:: chr(i, /) | |
.. function:: chr(codepoint, /) |
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 thought on changing this name, but then we need to change also the following text and the docstring "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."
@@ -846,7 +844,7 @@ are always available. They are listed here in alphabetical order. | |||
|
|||
|
|||
.. _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.
The empty frozenset is (notionally) a singleton, similar to the empty tuple, so I think it's clearer to distinguish them here:
.. class:: frozenset(iterable=(), /) | |
.. class:: frozenset() | |
frozenset(iterable, /) |
@@ -1144,8 +1142,7 @@ are always available. They are listed here in alphabetical order. | |||
|
|||
|
|||
.. _func-list: | |||
.. class:: list() | |||
list(iterable) | |||
.. class:: list(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.
As with frozenset I think clearer to keep two lines here:
.. class:: list(iterable=(), /) | |
.. class:: list() | |
list(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.
Your suggestions are opposite to @terryjreedy's. I just changed the code in opposite direction.
be removed - the name refers to the fact this method is usually used with | ||
ASCII characters. If omitted or ``None``, the *chars* argument defaults to | ||
removing ASCII whitespace. The *chars* argument is not a suffix; rather, | ||
ASCII characters. If omitted or ``None``, the *bytes* argument defaults to |
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 sentence no longer makes sense after changing the argument name
be removed - the name refers to the fact this method is usually used with | ||
ASCII characters. If omitted or ``None``, the *chars* argument defaults | ||
to removing ASCII whitespace. The *chars* argument is not a prefix; | ||
ASCII characters. If omitted or ``None``, the *bytes* argument defaults |
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 sentence no longer makes sense after changing the argument name
byte values to be removed - the name refers to the fact this method is | ||
usually used with ASCII characters. If omitted or ``None``, the *chars* | ||
argument defaults to removing ASCII whitespace. The *chars* argument is | ||
usually used with ASCII characters. If omitted or ``None``, the *bytes* |
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 sentence no longer makes sense after changing the argument name
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.
Could you please explain?
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.
Thank you for your review @AA-Turner, especially for your catch of stop/end misnaming.
You suggestions about constructors with no argument are opposite to @terryjreedy's. I have no strong preference for now. I will agree to any consensus.
Could you please explain what is wrong with bytes.strip()
etc?
|
||
As :func:`repr`, return a string containing a printable representation of an | ||
object, but escape the non-ASCII characters in the string returned by | ||
:func:`repr` using ``\x``, ``\u``, or ``\U`` escapes. This generates a string | ||
similar to that returned by :func:`repr` in Python 2. | ||
|
||
|
||
.. function:: bin(x) | ||
.. function:: bin(integer, /) |
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 initially used number
(it is used in the builtin signature), but changed it to integer, since only int
and objects implementing __index__
are supported. In many other parts of the documentation "integer" means "int
or objects implementing __index__
".
Doc/library/functions.rst
Outdated
@@ -244,7 +242,7 @@ are always available. They are listed here in alphabetical order. | |||
in Python 3.2. | |||
|
|||
|
|||
.. function:: chr(i) | |||
.. function:: chr(i, /) |
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 thought on changing this name, but then we need to change also the following text and the docstring "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."
Doc/library/functions.rst
Outdated
@@ -1562,7 +1559,7 @@ are always available. They are listed here in alphabetical order. | |||
.. versionchanged:: 3.11 | |||
The ``'U'`` mode has been removed. | |||
|
|||
.. function:: ord(c) | |||
.. function:: ord(c, /) |
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.
Hmm, the following text and the docstring are incorrect, they should be changed in any case.
@@ -1144,8 +1142,7 @@ are always available. They are listed here in alphabetical order. | |||
|
|||
|
|||
.. _func-list: | |||
.. class:: list() | |||
list(iterable) | |||
.. class:: list(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.
Your suggestions are opposite to @terryjreedy's. I just changed the code in opposite direction.
.. method:: hex(*, bytes_per_sep=1) | ||
hex(sep, bytes_per_sep=1) |
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 why I did not use this.
We can change the code (it would be not trivial) to support sep=''
, but this is a different issue.
Doc/library/functions.rst
Outdated
.. class:: type(object) | ||
type(name, bases, dict, **kwds) | ||
.. class:: type(object, /) | ||
type(name, bases, dict, /, **kwds) |
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 think that historically kwds
was used first, but now kwargs
is used 4-5 times more. kwds
is still used 93 times in the documentation and 519 in the Python code. It is not error, but we can change the name here.
byte values to be removed - the name refers to the fact this method is | ||
usually used with ASCII characters. If omitted or ``None``, the *chars* | ||
argument defaults to removing ASCII whitespace. The *chars* argument is | ||
usually used with ASCII characters. If omitted or ``None``, the *bytes* |
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.
Could you please explain?
|
||
Given a string representing one Unicode character, return an integer | ||
The argument must be a one-character string or a :class:`bytes` or |
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 created a separate issue for this: #137668.
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/