Skip to content

Commit ad4b000

Browse files
committed
Issue #14783: Backport changes from 3.2.
1 parent e4831f6 commit ad4b000

File tree

9 files changed

+44
-24
lines changed

9 files changed

+44
-24
lines changed

Doc/library/functions.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ available. They are listed here in alphabetical order.
733733
affect the values of local and free variables used by the interpreter.
734734

735735

736-
.. function:: long([x[, base]])
736+
.. function:: long(x=0)
737+
long(x, base=10)
737738

738739
Convert a string or number to a long integer. If the argument is a string, it
739740
must contain a possibly signed number of arbitrary size, possibly embedded in
@@ -1318,7 +1319,7 @@ available. They are listed here in alphabetical order.
13181319
Function decorator syntax added.
13191320

13201321

1321-
.. function:: str([object])
1322+
.. function:: str(object='')
13221323

13231324
Return a string containing a nicely printable representation of an object. For
13241325
strings, this returns the string itself. The difference with ``repr(object)``
@@ -1463,7 +1464,8 @@ available. They are listed here in alphabetical order.
14631464
.. versionadded:: 2.0
14641465

14651466

1466-
.. function:: unicode([object[, encoding [, errors]]])
1467+
.. function:: unicode(object='')
1468+
unicode(object[, encoding [, errors]])
14671469

14681470
Return the Unicode string version of *object* using one of the following modes:
14691471

Misc/NEWS

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

12+
- Issue #14783: Improve int() and long() docstrings and switch docstrings for
13+
unicode(), slice(), range(), and xrange() to use multi-line signatures.
14+
1215
- Issue #16030: Fix overflow bug in computing the `repr` of an xrange object
1316
with large start, step or length.
1417

Objects/intobject.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,15 +1334,20 @@ static PyGetSetDef int_getset[] = {
13341334
};
13351335

13361336
PyDoc_STRVAR(int_doc,
1337-
"int(x[, base]) -> integer\n\
1337+
"int(x=0) -> int or long\n\
1338+
int(x, base=10) -> int or long\n\
13381339
\n\
1339-
Convert a string or number to an integer, if possible. A floating point\n\
1340-
argument will be truncated towards zero (this does not include a string\n\
1341-
representation of a floating point number!) When converting a string, use\n\
1342-
the optional base. It is an error to supply a base when converting a\n\
1343-
non-string. If base is zero, the proper base is guessed based on the\n\
1344-
string content. If the argument is outside the integer range a\n\
1345-
long object will be returned instead.");
1340+
Convert a number or string to an integer, or return 0 if no arguments\n\
1341+
are given. If x is floating point, the conversion truncates towards zero.\n\
1342+
If x is outside the integer range, the function returns a long instead.\n\
1343+
\n\
1344+
If x is not a number or if base is given, then x must be a string or\n\
1345+
Unicode object representing an integer literal in the given base. The\n\
1346+
literal can be preceded by '+' or '-' and be surrounded by whitespace.\n\
1347+
The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to\n\
1348+
interpret the base from the string as an integer literal.\n\
1349+
>>> int('0b100', base=0)\n\
1350+
4");
13461351

13471352
static PyNumberMethods int_as_number = {
13481353
(binaryfunc)int_add, /*nb_add*/

Objects/longobject.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,13 +4221,19 @@ static PyGetSetDef long_getset[] = {
42214221
};
42224222

42234223
PyDoc_STRVAR(long_doc,
4224-
"long(x[, base]) -> integer\n\
4224+
"long(x=0) -> long\n\
4225+
long(x, base=10) -> long\n\
42254226
\n\
4226-
Convert a string or number to a long integer, if possible. A floating\n\
4227-
point argument will be truncated towards zero (this does not include a\n\
4228-
string representation of a floating point number!) When converting a\n\
4229-
string, use the optional base. It is an error to supply a base when\n\
4230-
converting a non-string.");
4227+
Convert a number or string to a long integer, or return 0L if no arguments\n\
4228+
are given. If x is floating point, the conversion truncates towards zero.\n\
4229+
\n\
4230+
If x is not a number or if base is given, then x must be a string or\n\
4231+
Unicode object representing an integer literal in the given base. The\n\
4232+
literal can be preceded by '+' or '-' and be surrounded by whitespace.\n\
4233+
The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to\n\
4234+
interpret the base from the string as an integer literal.\n\
4235+
>>> int('0b100', base=0)\n\
4236+
4L");
42314237

42324238
static PyNumberMethods long_as_number = {
42334239
(binaryfunc)long_add, /*nb_add*/

Objects/rangeobject.c

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

106106
PyDoc_STRVAR(range_doc,
107-
"xrange([start,] stop[, step]) -> xrange object\n\
107+
"xrange(stop) -> xrange object\n\
108+
xrange(start, stop[, step]) -> xrange object\n\
108109
\n\
109110
Like range(), but instead of returning a list, returns an object that\n\
110111
generates the numbers in the range on demand. For looping, this is \n\

Objects/sliceobject.c

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

213213
PyDoc_STRVAR(slice_doc,
214-
"slice([start,] stop[, step])\n\
214+
"slice(stop)\n\
215+
slice(start, stop[, step])\n\
215216
\n\
216217
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
217218

Objects/stringobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3799,7 +3799,7 @@ PyTypeObject PyBaseString_Type = {
37993799
};
38003800

38013801
PyDoc_STRVAR(string_doc,
3802-
"str(object) -> string\n\
3802+
"str(object='') -> string\n\
38033803
\n\
38043804
Return a nice string representation of the object.\n\
38053805
If the argument is a string, the return value is the same object.");

Objects/unicodeobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ char utf8_code_length[256] = {
18611861
illegal prefix. See RFC 3629 for details */
18621862
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00-0F */
18631863
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1864-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1864+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18651865
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18661866
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
18671867
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -2217,7 +2217,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
22172217
#endif
22182218
PyObject *errorHandler = NULL;
22192219
PyObject *exc = NULL;
2220-
2220+
22212221
q = (unsigned char *)s;
22222222
e = q + size;
22232223

@@ -8759,7 +8759,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
87598759
}
87608760

87618761
PyDoc_STRVAR(unicode_doc,
8762-
"unicode(string [, encoding[, errors]]) -> object\n\
8762+
"unicode(object='') -> unicode object\n\
8763+
unicode(string[, encoding[, errors]]) -> unicode object\n\
87638764
\n\
87648765
Create a new Unicode object from the given encoded string.\n\
87658766
encoding defaults to the current default string encoding.\n\

Python/bltinmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,8 @@ builtin_range(PyObject *self, PyObject *args)
20042004
}
20052005

20062006
PyDoc_STRVAR(range_doc,
2007-
"range([start,] stop[, step]) -> list of integers\n\
2007+
"range(stop) -> list of integers\n\
2008+
range(start, stop[, step]) -> list of integers\n\
20082009
\n\
20092010
Return a list containing an arithmetic progression of integers.\n\
20102011
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\

0 commit comments

Comments
 (0)