Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83fe2e1

Browse files
committed
Issue #14783: Improve int() docstring and also str(), range(), and slice().
This commit rewrites the docstring for int() to incorporate the documentation changes made in issue #16036. It also switches the docstrings for int(), str(), range(), and slice() to use multi-line signatures.
1 parent c3e5b10 commit 83fe2e1

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

Doc/library/functions.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,8 @@ are always available. They are listed here in alphabetical order.
12361236
standard type hierarchy in :ref:`types`.
12371237

12381238

1239-
.. function:: str([object[, encoding[, errors]]])
1239+
.. function:: str(object='')
1240+
str(object[, encoding[, errors]])
12401241

12411242
Return a string version of an object, using one of the following modes:
12421243

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #14783: Improve int() docstring and switch docstrings for str(),
14+
range(), and slice() to use multi-line signatures.
15+
1316
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap
1417
decoder (already working as unicode strings). Patch by Serhiy Storchaka.
1518

Objects/longobject.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,13 +4703,20 @@ static PyGetSetDef long_getset[] = {
47034703
};
47044704

47054705
PyDoc_STRVAR(long_doc,
4706-
"int(x[, base]) -> integer\n\
4706+
"int(x=0) -> integer\n\
4707+
int(x, base=10) -> integer\n\
47074708
\n\
4708-
Convert a string or number to an integer, if possible. A floating\n\
4709-
point argument will be truncated towards zero (this does not include a\n\
4710-
string representation of a floating point number!) When converting a\n\
4711-
string, use the optional base. It is an error to supply a base when\n\
4712-
converting a non-string.");
4709+
Convert a number or string to an integer, or return 0 if no arguments\n\
4710+
are given. If x is a number, return x.__int__(). For floating point\n\
4711+
numbers, this truncates towards zero.\n\
4712+
\n\
4713+
If x is not a number or if base is given, then x must be a string,\n\
4714+
bytes, or bytearray instance representing an integer literal in the\n\
4715+
given base. The literal can be preceded by '+' or '-' and be surrounded\n\
4716+
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n\
4717+
Base 0 means to interpret the base from the string as an integer literal.\n\
4718+
>>> int('0b100', base=0)\n\
4719+
4");
47134720

47144721
static PyNumberMethods long_as_number = {
47154722
(binaryfunc)long_add, /*nb_add*/

Objects/rangeobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
135135
}
136136

137137
PyDoc_STRVAR(range_doc,
138-
"range([start,] stop[, step]) -> range object\n\
138+
"range(stop) -> range object\n\
139+
range(start, stop[, step]) -> range object\n\
139140
\n\
140141
Returns a virtual sequence of numbers from start to stop by step.");
141142

Objects/sliceobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ slice_new(PyTypeObject *type, PyObject *args, PyObject *kw)
221221
}
222222

223223
PyDoc_STRVAR(slice_doc,
224-
"slice([start,] stop[, step])\n\
224+
"slice(stop)\n\
225+
slice(start, stop[, step])\n\
225226
\n\
226227
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
227228

Objects/unicodeobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9986,7 +9986,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
99869986
}
99879987

99889988
PyDoc_STRVAR(unicode_doc,
9989-
"str(object[, encoding[, errors]]) -> str\n\
9989+
"str(object='') -> str\n\
9990+
str(bytes_or_buffer[, encoding[, errors]]) -> str\n\
99909991
\n\
99919992
Create a new string object from the given object. If encoding or\n\
99929993
errors is specified, then the object must expose a data buffer\n\

0 commit comments

Comments
 (0)