[Python-checkins] r68748 - in python/branches/release30-maint: Doc/library/ctypes.rst Doc/library/datetime.rst Doc/library/random.rst Doc/library/stdtypes.rst Doc/reference/datamodel.rst Doc/reference/simple_stmts.rst Doc/tools/rstlint.py Lib/inspect.py Lib/test/test_codeccallbacks.py Modules/_ctypes/libffi_msvc/ffi.c Objects/exceptions.c Python/ast.c Python/compile.c

benjamin.peterson python-checkins at python.org
Sun Jan 18 23:40:43 CET 2009


Author: benjamin.peterson
Date: Sun Jan 18 23:40:43 2009
New Revision: 68748

Log:
Merged revisions 68746 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r68746 | benjamin.peterson | 2009-01-18 16:27:04 -0600 (Sun, 18 Jan 2009) | 55 lines
  
  Merged revisions 68633,68648,68667,68706,68718,68720-68721,68724-68727,68739 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r68633 | thomas.heller | 2009-01-16 12:53:44 -0600 (Fri, 16 Jan 2009) | 3 lines
    
    Change an example in the docs to avoid a mistake when the code is copy
    pasted and changed afterwards.
  ........
    r68648 | benjamin.peterson | 2009-01-16 22:28:57 -0600 (Fri, 16 Jan 2009) | 1 line
    
    use enumerate
  ........
    r68667 | amaury.forgeotdarc | 2009-01-17 14:18:59 -0600 (Sat, 17 Jan 2009) | 3 lines
    
    #4077: No need to append \n when calling Py_FatalError
    + fix a declaration to make it match the one in pythonrun.h
  ........
    r68706 | benjamin.peterson | 2009-01-17 19:28:46 -0600 (Sat, 17 Jan 2009) | 1 line
    
    fix grammar
  ........
    r68718 | georg.brandl | 2009-01-18 04:42:35 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4976: union() and intersection() take multiple args, but talk about "the other".
  ........
    r68720 | georg.brandl | 2009-01-18 04:45:22 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4974: fix redundant mention of lists and tuples.
  ........
    r68721 | georg.brandl | 2009-01-18 04:48:16 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4914: trunc is in math.
  ........
    r68724 | georg.brandl | 2009-01-18 07:24:10 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4979: correct result range for some random functions.
  ........
    r68725 | georg.brandl | 2009-01-18 07:47:26 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4857: fix augmented assignment target spec.
  ........
    r68726 | georg.brandl | 2009-01-18 08:41:52 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4923: clarify what was added.
  ........
    r68727 | georg.brandl | 2009-01-18 12:25:30 -0600 (Sun, 18 Jan 2009) | 1 line
    
    #4986: augassigns are not expressions.
  ........
    r68739 | benjamin.peterson | 2009-01-18 15:11:38 -0600 (Sun, 18 Jan 2009) | 1 line
    
    fix test that wasn't working as expected #4990
  ........
................


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Doc/library/ctypes.rst
   python/branches/release30-maint/Doc/library/datetime.rst
   python/branches/release30-maint/Doc/library/random.rst
   python/branches/release30-maint/Doc/library/stdtypes.rst
   python/branches/release30-maint/Doc/reference/datamodel.rst
   python/branches/release30-maint/Doc/reference/simple_stmts.rst
   python/branches/release30-maint/Doc/tools/rstlint.py
   python/branches/release30-maint/Lib/inspect.py
   python/branches/release30-maint/Lib/test/test_codeccallbacks.py
   python/branches/release30-maint/Modules/_ctypes/libffi_msvc/ffi.c
   python/branches/release30-maint/Objects/exceptions.c
   python/branches/release30-maint/Python/ast.c
   python/branches/release30-maint/Python/compile.c

Modified: python/branches/release30-maint/Doc/library/ctypes.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/ctypes.rst	(original)
+++ python/branches/release30-maint/Doc/library/ctypes.rst	Sun Jan 18 23:40:43 2009
@@ -2406,10 +2406,10 @@
                          ("hreftype", HREFTYPE)]
 
          class TYPEDESC(Structure):
+             _anonymous_ = ("u",)
              _fields_ = [("u", _U),
                          ("vt", VARTYPE)]
 
-             _anonymous_ = ("u",)
 
       The ``TYPEDESC`` structure describes a COM data type, the ``vt`` field
       specifies which one of the union fields is valid.  Since the ``u`` field

Modified: python/branches/release30-maint/Doc/library/datetime.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/datetime.rst	(original)
+++ python/branches/release30-maint/Doc/library/datetime.rst	Sun Jan 18 23:40:43 2009
@@ -1494,10 +1494,6 @@
 microseconds should not be used, as :class:`date` objects have no such
 values.  If they're used anyway, ``0`` is substituted for them.
 
-:class:`time` and :class:`datetime` objects support a ``%f`` format code
-which expands to the number of microseconds in the object, zero-padded on
-the left to six places.
-
 For a naive object, the ``%z`` and ``%Z`` format codes are replaced by empty
 strings.
 
@@ -1616,7 +1612,9 @@
 (1)
    When used with the :func:`strptime` function, the ``%f`` directive
    accepts from one to six digits and zero pads on the right.  ``%f`` is
-   an extension to the set of format characters in the C standard.
+   an extension to the set of format characters in the C standard (but
+   implemented separately in datetime objects, and therefore always
+   available).
 
 (2)
    When used with the :func:`strptime` function, the ``%p`` directive only affects

Modified: python/branches/release30-maint/Doc/library/random.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/random.rst	(original)
+++ python/branches/release30-maint/Doc/library/random.rst	Sun Jan 18 23:40:43 2009
@@ -149,13 +149,13 @@
 
 .. function:: uniform(a, b)
 
-   Return a random floating point number *N* such that ``a <= N < b`` for
-   ``a <= b`` and ``b <= N < a`` for ``b < a``.
+   Return a random floating point number *N* such that ``a <= N <= b`` for
+   ``a <= b`` and ``b <= N <= a`` for ``b < a``.
 
 
 .. function:: triangular(low, high, mode)
 
-   Return a random floating point number *N* such that ``low <= N < high`` and
+   Return a random floating point number *N* such that ``low <= N <= high`` and
    with the specified *mode* between those bounds.  The *low* and *high* bounds
    default to zero and one.  The *mode* argument defaults to the midpoint
    between the bounds, giving a symmetric distribution.
@@ -163,8 +163,8 @@
 
 .. function:: betavariate(alpha, beta)
 
-   Beta distribution.  Conditions on the parameters are ``alpha > 0`` and ``beta >
-   0``. Returned values range between 0 and 1.
+   Beta distribution.  Conditions on the parameters are ``alpha > 0`` and
+   ``beta > 0``. Returned values range between 0 and 1.
 
 
 .. function:: expovariate(lambd)
@@ -176,14 +176,15 @@
 
 .. function:: gammavariate(alpha, beta)
 
-   Gamma distribution.  (*Not* the gamma function!)  Conditions on the parameters
-   are ``alpha > 0`` and ``beta > 0``.
+   Gamma distribution.  (*Not* the gamma function!)  Conditions on the
+   parameters are ``alpha > 0`` and ``beta > 0``.
 
 
 .. function:: gauss(mu, sigma)
 
-   Gaussian distribution.  *mu* is the mean, and *sigma* is the standard deviation.
-   This is slightly faster than the :func:`normalvariate` function defined below.
+   Gaussian distribution.  *mu* is the mean, and *sigma* is the standard
+   deviation.  This is slightly faster than the :func:`normalvariate` function
+   defined below.
 
 
 .. function:: lognormvariate(mu, sigma)

Modified: python/branches/release30-maint/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/stdtypes.rst	(original)
+++ python/branches/release30-maint/Doc/library/stdtypes.rst	Sun Jan 18 23:40:43 2009
@@ -343,19 +343,19 @@
 All :class:`numbers.Real` types (:class:`int` and
 :class:`float`) also include the following operations:
 
-+--------------------+--------------------------------+--------+
-| Operation          | Result                         | Notes  |
-+====================+================================+========+
-| ``trunc(x)``       | *x* truncated to Integral      |        |
-+--------------------+--------------------------------+--------+
-| ``round(x[, n])``  | *x* rounded to n digits,       |        |
-|                    | rounding half to even. If n is |        |
-|                    | omitted, it defaults to 0.     |        |
-+--------------------+--------------------------------+--------+
-| ``math.floor(x)``  | the greatest Integral <= *x*   |        |
-+--------------------+--------------------------------+--------+
-| ``math.ceil(x)``   | the least Integral >= *x*      |        |
-+--------------------+--------------------------------+--------+
++--------------------+------------------------------------+--------+
+| Operation          | Result                             | Notes  |
++====================+====================================+========+
+| ``math.trunc(x)``  | *x* truncated to Integral          |        |
++--------------------+------------------------------------+--------+
+| ``round(x[, n])``  | *x* rounded to n digits,           |        |
+|                    | rounding half to even. If n is     |        |
+|                    | omitted, it defaults to 0.         |        |
++--------------------+------------------------------------+--------+
+| ``math.floor(x)``  | the greatest integral float <= *x* |        |
++--------------------+------------------------------------+--------+
+| ``math.ceil(x)``   | the least integral float >= *x*    |        |
++--------------------+------------------------------------+--------+
 
 For additional numeric operations see the :mod:`math` and :mod:`cmath`
 modules.
@@ -420,6 +420,36 @@
    overflow check.
 
 
+Additional Methods on Integer Types
+-----------------------------------
+
+.. method:: int.bit_length()
+
+    Return the number of bits necessary to represent an integer in binary,
+    excluding the sign and leading zeros::
+
+        >>> n = -37
+        >>> bin(n)
+        '-0b100101'
+        >>> n.bit_length()
+        6
+
+    More precisely, if ``x`` is nonzero, then ``x.bit_length()`` is the
+    unique positive integer ``k`` such that ``2**(k-1) <= abs(x) < 2**k``.
+    Equivalently, when ``abs(x)`` is small enough to have a correctly
+    rounded logarithm, then ``k = 1 + int(log(abs(x), 2))``.
+    If ``x`` is zero, then ``x.bit_length()`` returns ``0``.
+
+    Equivalent to::
+
+        def bit_length(self):
+            s = bin(x)          # binary representation:  bin(-37) --> '-0b100101'
+            s = s.lstrip('-0b') # remove leading zeros and minus sign
+            return len(s)       # len('100101') --> 6
+
+    .. versionadded:: 3.1
+
+
 Additional Methods on Float
 ---------------------------
 
@@ -564,16 +594,17 @@
 Sequence Types --- :class:`str`, :class:`bytes`, :class:`bytearray`, :class:`list`, :class:`tuple`, :class:`range`
 ==================================================================================================================
 
-There are five sequence types: strings, byte sequences, byte arrays, lists,
-tuples, and range objects.  (For other containers see the built-in
-:class:`dict`, :class:`list`, :class:`set`, and :class:`tuple` classes, and the
-:mod:`collections` module.)
+There are six sequence types: strings, byte sequences (:class:`bytes` objects),
+byte arrays (:class:`bytearray` objects), lists, tuples, and range objects.  For
+other containers see the built in :class:`dict` and :class:`set` classes, and
+the :mod:`collections` module.
+
 
 .. index::
    object: sequence
    object: string
    object: bytes
-   object: buffer
+   object: bytearray
    object: tuple
    object: list
    object: range
@@ -1592,12 +1623,12 @@
    .. method:: union(other, ...)
                set | other | ...
 
-      Return a new set with elements from both sets.
+      Return a new set with elements from the set and all others.
 
    .. method:: intersection(other, ...)
                set & other & ...
 
-      Return a new set with elements common to both sets.
+      Return a new set with elements common to the set and all others.
 
    .. method:: difference(other, ...)
                set - other - ...

Modified: python/branches/release30-maint/Doc/reference/datamodel.rst
==============================================================================
--- python/branches/release30-maint/Doc/reference/datamodel.rst	(original)
+++ python/branches/release30-maint/Doc/reference/datamodel.rst	Sun Jan 18 23:40:43 2009
@@ -317,7 +317,7 @@
       slicing notations can be used as the target of assignment and :keyword:`del`
       (delete) statements.
 
-      There is currently a single intrinsic mutable sequence type:
+      There are currently two intrinsic mutable sequence types:
 
       Lists
          .. index:: object: list
@@ -1777,13 +1777,13 @@
             object.__ixor__(self, other)
             object.__ior__(self, other)
 
-   These methods are called to implement the augmented arithmetic operations
+   These methods are called to implement the augmented arithmetic assignments
    (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``, ``**=``, ``<<=``, ``>>=``,
    ``&=``, ``^=``, ``|=``).  These methods should attempt to do the operation
    in-place (modifying *self*) and return the result (which could be, but does
    not have to be, *self*).  If a specific method is not defined, the augmented
-   operation falls back to the normal methods.  For instance, to evaluate the
-   expression ``x += y``, where *x* is an instance of a class that has an
+   assignment falls back to the normal methods.  For instance, to execute the
+   statement ``x += y``, where *x* is an instance of a class that has an
    :meth:`__iadd__` method, ``x.__iadd__(y)`` is called.  If *x* is an instance
    of a class that does not define a :meth:`__iadd__` method, ``x.__add__(y)``
    and ``y.__radd__(x)`` are considered, as with the evaluation of ``x + y``.

Modified: python/branches/release30-maint/Doc/reference/simple_stmts.rst
==============================================================================
--- python/branches/release30-maint/Doc/reference/simple_stmts.rst	(original)
+++ python/branches/release30-maint/Doc/reference/simple_stmts.rst	Sun Jan 18 23:40:43 2009
@@ -246,7 +246,8 @@
 operation and an assignment statement:
 
 .. productionlist::
-   augmented_assignment_stmt: `target` `augop` (`expression_list` | `yield_expression`)
+   augmented_assignment_stmt: `augtarget` `augop` (`expression_list` | `yield_expression`)
+   augtarget: `identifier` | `attributeref` | `subscription` | `slicing`
    augop: "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="
         : | ">>=" | "<<=" | "&=" | "^=" | "|="
 

Modified: python/branches/release30-maint/Doc/tools/rstlint.py
==============================================================================
--- python/branches/release30-maint/Doc/tools/rstlint.py	(original)
+++ python/branches/release30-maint/Doc/tools/rstlint.py	Sun Jan 18 23:40:43 2009
@@ -6,6 +6,9 @@
 #
 # 01/2009, Georg Brandl
 
+# TODO: - wrong versions in versionadded/changed
+#       - wrong markup after versionchanged directive
+
 from __future__ import with_statement
 
 import os

Modified: python/branches/release30-maint/Lib/inspect.py
==============================================================================
--- python/branches/release30-maint/Lib/inspect.py	(original)
+++ python/branches/release30-maint/Lib/inspect.py	Sun Jan 18 23:40:43 2009
@@ -881,8 +881,8 @@
     specs = []
     if defaults:
         firstdefault = len(args) - len(defaults)
-    for i in range(len(args)):
-        spec = strseq(args[i], formatargandannotation, join)
+    for i, arg in enumerate(args):
+        spec = strseq(arg, formatargandannotation, join)
         if defaults and i >= firstdefault:
             spec = spec + formatvalue(defaults[i - firstdefault])
         specs.append(spec)

Modified: python/branches/release30-maint/Lib/test/test_codeccallbacks.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_codeccallbacks.py	(original)
+++ python/branches/release30-maint/Lib/test/test_codeccallbacks.py	Sun Jan 18 23:40:43 2009
@@ -592,7 +592,7 @@
         encs = ("ascii", "latin-1", "iso-8859-1", "iso-8859-15")
 
         for res in results:
-            codecs.register_error("test.badhandler", lambda: res)
+            codecs.register_error("test.badhandler", lambda x: res)
             for enc in encs:
                 self.assertRaises(
                     TypeError,

Modified: python/branches/release30-maint/Modules/_ctypes/libffi_msvc/ffi.c
==============================================================================
--- python/branches/release30-maint/Modules/_ctypes/libffi_msvc/ffi.c	(original)
+++ python/branches/release30-maint/Modules/_ctypes/libffi_msvc/ffi.c	Sun Jan 18 23:40:43 2009
@@ -34,7 +34,7 @@
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments */
 
-extern void Py_FatalError(char *msg);
+extern void Py_FatalError(const char *msg);
 
 /*@-exportheader@*/
 void ffi_prep_args(char *stack, extended_cif *ecif)

Modified: python/branches/release30-maint/Objects/exceptions.c
==============================================================================
--- python/branches/release30-maint/Objects/exceptions.c	(original)
+++ python/branches/release30-maint/Objects/exceptions.c	Sun Jan 18 23:40:43 2009
@@ -1923,7 +1923,7 @@
 
     PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL);
     if (!PyExc_MemoryErrorInst)
-        Py_FatalError("Cannot pre-allocate MemoryError instance\n");
+        Py_FatalError("Cannot pre-allocate MemoryError instance");
 
     PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
     if (!PyExc_RecursionErrorInst)

Modified: python/branches/release30-maint/Python/ast.c
==============================================================================
--- python/branches/release30-maint/Python/ast.c	(original)
+++ python/branches/release30-maint/Python/ast.c	Sun Jan 18 23:40:43 2009
@@ -191,7 +191,7 @@
         default: {
             char buf[128];
 
-            sprintf(buf, "Non-statement found: %d %d\n",
+            sprintf(buf, "Non-statement found: %d %d",
                     TYPE(n), NCH(n));
             Py_FatalError(buf);
         }

Modified: python/branches/release30-maint/Python/compile.c
==============================================================================
--- python/branches/release30-maint/Python/compile.c	(original)
+++ python/branches/release30-maint/Python/compile.c	Sun Jan 18 23:40:43 2009
@@ -1237,7 +1237,7 @@
 	    char buf[350];
 	    PyOS_snprintf(buf, sizeof(buf),
 			  "unknown scope for %.100s in %.100s(%s) in %s\n"
-			  "symbols: %s\nlocals: %s\nglobals: %s\n",
+			  "symbols: %s\nlocals: %s\nglobals: %s",
 			  PyBytes_AS_STRING(name), 
 			  PyBytes_AS_STRING(c->u->u_name), 
 			  PyObject_REPR(c->u->u_ste->ste_id),


More information about the Python-checkins mailing list