summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-10-07 21:48:36 (GMT)
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-10-07 21:48:36 (GMT)
commit83fe2e1c22e6ff72a308e82e1e24ca03f8c51339 (patch)
treef8e8071faf6e7d06b812c8fa9090c41c57ad91d3 /Objects
parentc3e5b10ae76c3ffe8672e91a5478a19e35b60220 (diff)
downloadcpython-83fe2e1c22e6ff72a308e82e1e24ca03f8c51339.zip
cpython-83fe2e1c22e6ff72a308e82e1e24ca03f8c51339.tar.gz
cpython-83fe2e1c22e6ff72a308e82e1e24ca03f8c51339.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c19
-rw-r--r--Objects/rangeobject.c3
-rw-r--r--Objects/sliceobject.c3
-rw-r--r--Objects/unicodeobject.c3
4 files changed, 19 insertions, 9 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index dfedfb7..b9a0d85 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -4703,13 +4703,20 @@ static PyGetSetDef long_getset[] = {
};
PyDoc_STRVAR(long_doc,
-"int(x[, base]) -> integer\n\
+"int(x=0) -> integer\n\
+int(x, base=10) -> integer\n\
\n\
-Convert a string or number to an integer, if possible. A floating\n\
-point argument will be truncated towards zero (this does not include a\n\
-string representation of a floating point number!) When converting a\n\
-string, use the optional base. It is an error to supply a base when\n\
-converting a non-string.");
+Convert a number or string to an integer, or return 0 if no arguments\n\
+are given. If x is a number, return x.__int__(). For floating point\n\
+numbers, this truncates towards zero.\n\
+\n\
+If x is not a number or if base is given, then x must be a string,\n\
+bytes, or bytearray instance representing an integer literal in the\n\
+given base. The literal can be preceded by '+' or '-' and be surrounded\n\
+by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n\
+Base 0 means to interpret the base from the string as an integer literal.\n\
+>>> int('0b100', base=0)\n\
+4");
static PyNumberMethods long_as_number = {
(binaryfunc)long_add, /*nb_add*/
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 935b205..b67b969 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -135,7 +135,8 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(range_doc,
-"range([start,] stop[, step]) -> range object\n\
+"range(stop) -> range object\n\
+range(start, stop[, step]) -> range object\n\
\n\
Returns a virtual sequence of numbers from start to stop by step.");
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index d7b97c9..0f4b647 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -221,7 +221,8 @@ slice_new(PyTypeObject *type, PyObject *args, PyObject *kw)
}
PyDoc_STRVAR(slice_doc,
-"slice([start,] stop[, step])\n\
+"slice(stop)\n\
+slice(start, stop[, step])\n\
\n\
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index f59db36..1dd3a85 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9986,7 +9986,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
PyDoc_STRVAR(unicode_doc,
- "str(object[, encoding[, errors]]) -> str\n\
+"str(object='') -> str\n\
+str(bytes_or_buffer[, encoding[, errors]]) -> str\n\
\n\
Create a new string object from the given object. If encoding or\n\
errors is specified, then the object must expose a data buffer\n\