Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/reference/datamodel.rst

    r2 r391  
    6767   module for information on controlling the collection of cyclic garbage.
    6868   Other implementations act differently and CPython may change.
     69   Do not depend on immediate finalization of objects when they become
     70   unreachable (ex: always close files).
    6971
    7072Note that the use of the implementation's tracing or debugging facilities may
     
    410412      These represent a mutable set. They are created by the built-in :func:`set`
    411413      constructor and can be modified afterwards by several methods, such as
    412       :meth:`add`.
     414      :meth:`~set.add`.
    413415
    414416   Frozen sets
     
    479481
    480482      Special attributes:
     483
     484      .. tabularcolumns:: |l|L|l|
    481485
    482486      +-----------------------+-------------------------------+-----------+
     
    572576
    573577      .. versionchanged:: 2.6
    574          For 3.0 forward-compatibility, :attr:`im_func` is also available as
     578         For Python 3 forward-compatibility, :attr:`im_func` is also available as
    575579         :attr:`__func__`, and :attr:`im_self` as :attr:`__self__`.
    576580
     
    620624
    621625      When a user-defined method object is created by retrieving a class method object
    622       from a class or instance, its :attr:`im_self` attribute is the class itself (the
    623       same as the :attr:`im_class` attribute), and its :attr:`im_func` attribute is
    624       the function object underlying the class method.
     626      from a class or instance, its :attr:`im_self` attribute is the class itself, and
     627      its :attr:`im_func` attribute is the function object underlying the class method.
    625628
    626629      When an unbound user-defined method object is called, the underlying function
     
    659662      function`.  Such a function, when called, always returns an iterator object
    660663      which can be used to execute the body of the function:  calling the iterator's
    661       :meth:`next` method will cause the function to execute until it provides a value
     664      :meth:`~iterator.next` method will cause the function to execute until
     665      it provides a value
    662666      using the :keyword:`yield` statement.  When the function executes a
    663667      :keyword:`return` statement or falls off the end, a :exc:`StopIteration`
     
    690694      a built-in method is ``alist.append()``, assuming *alist* is a list object. In
    691695      this case, the special read-only attribute :attr:`__self__` is set to the object
    692       denoted by *list*.
     696      denoted by *alist*.
    693697
    694698   Class Types
     
    739743   Special read-only attribute: :attr:`__dict__` is the module's namespace as a
    740744   dictionary object.
     745
     746   .. impl-detail::
     747
     748      Because of the way CPython clears module dictionaries, the module
     749      dictionary will be cleared when the module falls out of scope even if the
     750      dictionary still has live references.  To avoid this, copy the dictionary
     751      or keep the module around while using its dictionary directly.
    741752
    742753   .. index::
     
    787798   transformed into an unbound user-defined method object whose :attr:`im_class`
    788799   attribute is :class:`C`. When it would yield a class method object, it is
    789    transformed into a bound user-defined method object whose :attr:`im_class`
    790    and :attr:`im_self` attributes are both :class:`C`.  When it would yield a
     800   transformed into a bound user-defined method object whose
     801   :attr:`im_self` attribute is :class:`C`.  When it would yield a
    791802   static method object, it is transformed into the object wrapped by the static
    792803   method object. See section :ref:`descriptors` for another way in which
     
    812823   Special attributes: :attr:`__name__` is the class name; :attr:`__module__` is
    813824   the module name in which the class was defined; :attr:`__dict__` is the
    814    dictionary containing the class's namespace; :attr:`__bases__` is a tuple
    815    (possibly empty or a singleton) containing the base classes, in the order of
    816    their occurrence in the base class list; :attr:`__doc__` is the class's
    817    documentation string, or None if undefined.
     825   dictionary containing the class's namespace; :attr:`~class.__bases__` is a
     826   tuple (possibly empty or a singleton) containing the base classes, in the
     827   order of their occurrence in the base class list; :attr:`__doc__` is the
     828   class's documentation string, or None if undefined.
    818829
    819830Class instances
     
    860871      single: __class__ (instance attribute)
    861872
    862    Special attributes: :attr:`__dict__` is the attribute dictionary;
    863    :attr:`__class__` is the instance's class.
     873   Special attributes: :attr:`~object.__dict__` is the attribute dictionary;
     874   :attr:`~instance.__class__` is the instance's class.
    864875
    865876Files
     
    908919      objects, code objects are immutable and contain no references (directly or
    909920      indirectly) to mutable objects.
     921
     922      .. index::
     923         single: co_argcount (code object attribute)
     924         single: co_code (code object attribute)
     925         single: co_consts (code object attribute)
     926         single: co_filename (code object attribute)
     927         single: co_firstlineno (code object attribute)
     928         single: co_flags (code object attribute)
     929         single: co_lnotab (code object attribute)
     930         single: co_name (code object attribute)
     931         single: co_names (code object attribute)
     932         single: co_nlocals (code object attribute)
     933         single: co_stacksize (code object attribute)
     934         single: co_varnames (code object attribute)
     935         single: co_cellvars (code object attribute)
     936         single: co_freevars (code object attribute)
    910937
    911938      Special read-only attributes: :attr:`co_name` gives the function name;
     
    926953      :attr:`co_flags` is an integer encoding a number of flags for the interpreter.
    927954
    928       .. index::
    929          single: co_argcount (code object attribute)
    930          single: co_code (code object attribute)
    931          single: co_consts (code object attribute)
    932          single: co_filename (code object attribute)
    933          single: co_firstlineno (code object attribute)
    934          single: co_flags (code object attribute)
    935          single: co_lnotab (code object attribute)
    936          single: co_name (code object attribute)
    937          single: co_names (code object attribute)
    938          single: co_nlocals (code object attribute)
    939          single: co_stacksize (code object attribute)
    940          single: co_varnames (code object attribute)
    941          single: co_cellvars (code object attribute)
    942          single: co_freevars (code object attribute)
    943 
    944955      .. index:: object: generator
    945956
     
    10601071         single: step (slice object attribute)
    10611072
    1062       Special read-only attributes: :attr:`start` is the lower bound; :attr:`stop` is
    1063       the upper bound; :attr:`step` is the step value; each is ``None`` if omitted.
    1064       These attributes can have any type.
     1073      Special read-only attributes: :attr:`~slice.start` is the lower bound;
     1074      :attr:`~slice.stop` is the upper bound; :attr:`~slice.step` is the step
     1075      value; each is ``None`` if omitted.  These attributes can have any type.
    10651076
    10661077      Slice objects support one method:
     
    11411152   single: class; old-style
    11421153
    1143 Old-style classes are removed in Python 3.0, leaving only the semantics of
     1154Old-style classes are removed in Python 3, leaving only the semantics of
    11441155new-style classes.
    11451156
     
    11691180object being modelled.  For example, some sequences may work well with retrieval
    11701181of individual elements, but extracting a slice may not make sense.  (One example
    1171 of this is the :class:`NodeList` interface in the W3C's Document Object Model.)
     1182of this is the :class:`~xml.dom.NodeList` interface in the W3C's Document
     1183Object Model.)
    11721184
    11731185
     
    12741286      called.
    12751287
     1288   See also the :option:`-R` command-line option.
     1289
    12761290
    12771291.. method:: object.__repr__(self)
     
    13541368
    13551369   To automatically generate ordering operations from a single root operation,
    1356    see the `Total Ordering recipe in the ASPN cookbook
    1357    <http://code.activestate.com/recipes/576529/>`_\.
     1370   see :func:`functools.total_ordering`.
    13581371
    13591372.. method:: object.__cmp__(self, other)
     
    15321545
    15331546The following methods only apply when an instance of the class containing the
    1534 method (a so-called *descriptor* class) appears in the class dictionary of
    1535 another new-style class, known as the *owner* class. In the examples below, "the
    1536 attribute" refers to the attribute whose name is the key of the property in the
    1537 owner class' ``__dict__``.  Descriptors can only be implemented as new-style
    1538 classes themselves.
     1547method (a so-called *descriptor* class) appears in an *owner* class (the
     1548descriptor must be in either the owner's class dictionary or in the class
     1549dictionary for one of its parents).  In the examples below, "the attribute"
     1550refers to the attribute whose name is the key of the property in the owner
     1551class' :attr:`__dict__`.
    15391552
    15401553
     
    16011614   obj).m()`` searches ``obj.__class__.__mro__`` for the base class ``A``
    16021615   immediately preceding ``B`` and then invokes the descriptor with the call:
    1603    ``A.__dict__['m'].__get__(obj, A)``.
     1616   ``A.__dict__['m'].__get__(obj, obj.__class__)``.
    16041617
    16051618For instance bindings, the precedence of descriptor invocation depends on the
    1606 which descriptor methods are defined.  Normally, data descriptors define both
    1607 :meth:`__get__` and :meth:`__set__`, while non-data descriptors have just the
    1608 :meth:`__get__` method.  Data descriptors always override a redefinition in an
     1619which descriptor methods are defined.  A descriptor can define any combination
     1620of :meth:`__get__`, :meth:`__set__` and :meth:`__delete__`.  If it does not
     1621define :meth:`__get__`, then accessing the attribute will return the descriptor
     1622object itself unless there is a value in the object's instance dictionary.  If
     1623the descriptor defines :meth:`__set__` and/or :meth:`__delete__`, it is a data
     1624descriptor; if it defines neither, it is a non-data descriptor.  Normally, data
     1625descriptors define both :meth:`__get__` and :meth:`__set__`, while non-data
     1626descriptors have just the :meth:`__get__` method.  Data descriptors with
     1627:meth:`__set__` and :meth:`__get__` defined always override a redefinition in an
    16091628instance dictionary.  In contrast, non-data descriptors can be overridden by
    1610 instances. [#]_
     1629instances.
    16111630
    16121631Python methods (including :func:`staticmethod` and :func:`classmethod`) are
     
    17561775property creation, proxies, frameworks, and automatic resource
    17571776locking/synchronization.
     1777
     1778
     1779Customizing instance and subclass checks
     1780----------------------------------------
     1781
     1782.. versionadded:: 2.6
     1783
     1784The following methods are used to override the default behavior of the
     1785:func:`isinstance` and :func:`issubclass` built-in functions.
     1786
     1787In particular, the metaclass :class:`abc.ABCMeta` implements these methods in
     1788order to allow the addition of Abstract Base Classes (ABCs) as "virtual base
     1789classes" to any class or type (including built-in types), including other
     1790ABCs.
     1791
     1792.. method:: class.__instancecheck__(self, instance)
     1793
     1794   Return true if *instance* should be considered a (direct or indirect)
     1795   instance of *class*. If defined, called to implement ``isinstance(instance,
     1796   class)``.
     1797
     1798
     1799.. method:: class.__subclasscheck__(self, subclass)
     1800
     1801   Return true if *subclass* should be considered a (direct or indirect)
     1802   subclass of *class*.  If defined, called to implement ``issubclass(subclass,
     1803   class)``.
     1804
     1805
     1806Note that these methods are looked up on the type (metaclass) of a class.  They
     1807cannot be defined as class methods in the actual class.  This is consistent with
     1808the lookup of special methods that are called on instances, only in this
     1809case the instance is itself a class.
     1810
     1811.. seealso::
     1812
     1813   :pep:`3119` - Introducing Abstract Base Classes
     1814      Includes the specification for customizing :func:`isinstance` and
     1815      :func:`issubclass` behavior through :meth:`~class.__instancecheck__` and
     1816      :meth:`~class.__subclasscheck__`, with motivation for this functionality
     1817      in the context of adding Abstract Base Classes (see the :mod:`abc`
     1818      module) to the language.
    17581819
    17591820
     
    17881849:meth:`values`, :meth:`items`, :meth:`has_key`, :meth:`get`, :meth:`clear`,
    17891850:meth:`setdefault`, :meth:`iterkeys`, :meth:`itervalues`, :meth:`iteritems`,
    1790 :meth:`pop`, :meth:`popitem`, :meth:`copy`, and :meth:`update` behaving similar
     1851:meth:`pop`, :meth:`popitem`, :meth:`!copy`, and :meth:`update` behaving similar
    17911852to those for Python's standard dictionary objects.  The :mod:`UserDict` module
    17921853provides a :class:`DictMixin` class to help create those methods from a base set
     
    21782239evolved, the coercion rules have become hard to document precisely; documenting
    21792240what one version of one particular implementation does is undesirable.  Instead,
    2180 here are some informal guidelines regarding coercion.  In Python 3.0, coercion
     2241here are some informal guidelines regarding coercion.  In Python 3, coercion
    21812242will not be supported.
    21822243
     
    22532314*
    22542315
    2255   In ``x * y``, if one operator is a sequence that implements sequence
     2316  In ``x * y``, if one operand is a sequence that implements sequence
    22562317  repetition, and the other is an integer (:class:`int` or :class:`long`),
    22572318  sequence repetition is invoked.
     
    22662327
    22672328  In the current implementation, the built-in numeric types :class:`int`,
    2268   :class:`long` and :class:`float` do not use coercion; the type :class:`complex`
    2269   however does use coercion for binary operators and rich comparisons, despite
    2270   the above rules.  The difference can become apparent when subclassing these
    2271   types.  Over time, the type :class:`complex` may be fixed to avoid coercion.
     2329  :class:`long`, :class:`float`, and :class:`complex` do not use coercion.
    22722330  All these types implement a :meth:`__coerce__` method, for use by the built-in
    22732331  :func:`coerce` function.
     2332
     2333  .. versionchanged:: 2.7
     2334
     2335     The complex type no longer makes implicit calls to the :meth:`__coerce__`
     2336     method for mixed-type binary arithmetic operations.
    22742337
    22752338
     
    24352498   lead to some very strange behaviour if it is handled incorrectly.
    24362499
    2437 .. [#] A descriptor can define any combination of :meth:`__get__`,
    2438    :meth:`__set__` and :meth:`__delete__`.  If it does not define :meth:`__get__`,
    2439    then accessing the attribute even on an instance will return the descriptor
    2440    object itself.  If the descriptor defines :meth:`__set__` and/or
    2441    :meth:`__delete__`, it is a data descriptor; if it defines neither, it is a
    2442    non-data descriptor.
    2443 
    24442500.. [#] For operands of the same type, it is assumed that if the non-reflected method
    24452501   (such as :meth:`__add__`) fails the operation is not supported, which is why the
Note: See TracChangeset for help on using the changeset viewer.