]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #14783: Improve int() docstring and also str(), range(), and slice().
authorChris Jerdonek <chris.jerdonek@gmail.com>
Sun, 7 Oct 2012 21:48:36 +0000 (14:48 -0700)
committerChris Jerdonek <chris.jerdonek@gmail.com>
Sun, 7 Oct 2012 21:48:36 +0000 (14:48 -0700)
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.

Doc/library/functions.rst
Misc/NEWS
Objects/longobject.c
Objects/rangeobject.c
Objects/sliceobject.c
Objects/unicodeobject.c

index 1ee8540b0963bdc41fa06c77a19447dcb6d007cb..2575d7f787974cf18c142625beb37dd10bd35f6b 100644 (file)
@@ -1236,7 +1236,8 @@ are always available.  They are listed here in alphabetical order.
    standard type hierarchy in :ref:`types`.
 
 
-.. function:: str([object[, encoding[, errors]]])
+.. function:: str(object='')
+              str(object[, encoding[, errors]])
 
    Return a string version of an object, using one of the following modes:
 
index bc5470aac9054e4489c0c57a3b0ada9936b13fa9..5cd69b415276fef2b6b3a378bad7b5f334285dfa 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #14783: Improve int() docstring and switch docstrings for str(),
+  range(), and slice() to use multi-line signatures.
+
 - Issue #15379: Fix passing of non-BMP characters as integers for the charmap
   decoder (already working as unicode strings).  Patch by Serhiy Storchaka.
 
index dfedfb7bfec4c5197764154eb0c95936e9288a6e..b9a0d8543a63166ea7593b9e9e4d8a2dec7deb84 100644 (file)
@@ -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*/
index 935b205111aa75cfba7e11b7dc3136bf63bf982c..b67b9694d58aaacea0c210c7e1237b715a84d599 100644 (file)
@@ -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.");
 
index d7b97c9699ad88af907cb6950e1da2aa60b2fd33..0f4b64796519816ab035ffc19f9ea731f6ef8fbd 100644 (file)
@@ -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]).");
 
index f59db36dd3d455c241aecfca5fa02300d490b43b..1dd3a852f27ddd605a6b8840276919d33de9cffe 100644 (file)
@@ -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\