~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Doc/reference/datamodel.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
they may be garbage-collected.  An implementation is allowed to postpone garbage
57
57
collection or omit it altogether --- it is a matter of implementation quality
58
58
how garbage collection is implemented, as long as no objects are collected that
59
 
are still reachable.  (Implementation note: CPython currently uses a
60
 
reference-counting scheme with (optional) delayed detection of cyclically linked
61
 
garbage, which collects most objects as soon as they become unreachable, but is
62
 
not guaranteed to collect garbage containing circular references.  See the
63
 
documentation of the :mod:`gc` module for information on controlling the
64
 
collection of cyclic garbage.  Other implementations act differently and CPython
65
 
may change.)
 
59
are still reachable.
 
60
 
 
61
.. impl-detail::
 
62
 
 
63
   CPython currently uses a reference-counting scheme with (optional) delayed
 
64
   detection of cyclically linked garbage, which collects most objects as soon
 
65
   as they become unreachable, but is not guaranteed to collect garbage
 
66
   containing circular references.  See the documentation of the :mod:`gc`
 
67
   module for information on controlling the collection of cyclic garbage.
 
68
   Other implementations act differently and CPython may change.
66
69
 
67
70
Note that the use of the implementation's tracing or debugging facilities may
68
71
keep objects alive that would normally be collectable. Also note that catching
360
363
      slicing notations can be used as the target of assignment and :keyword:`del`
361
364
      (delete) statements.
362
365
 
363
 
      There is currently a single intrinsic mutable sequence type:
 
366
      There are currently two intrinsic mutable sequence types:
364
367
 
365
368
      Lists
366
369
         .. index:: object: list
369
372
         comma-separated list of expressions in square brackets. (Note that there are no
370
373
         special cases needed to form lists of length 0 or 1.)
371
374
 
 
375
      Byte Arrays
 
376
         .. index:: bytearray
 
377
 
 
378
         A bytearray object is a mutable array. They are created by the built-in
 
379
         :func:`bytearray` constructor.  Aside from being mutable (and hence
 
380
         unhashable), byte arrays otherwise provide the same interface and
 
381
         functionality as immutable bytes objects.
 
382
 
372
383
      .. index:: module: array
373
384
 
374
385
      The extension module :mod:`array` provides an additional example of a mutable
951
962
      If a code object represents a function, the first item in :attr:`co_consts` is
952
963
      the documentation string of the function, or ``None`` if undefined.
953
964
 
 
965
   .. _frame-objects:
 
966
 
954
967
   Frame objects
955
968
      .. index:: object: frame
956
969
 
1339
1352
 
1340
1353
   Arguments to rich comparison methods are never coerced.
1341
1354
 
 
1355
   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/>`_\.
1342
1358
 
1343
1359
.. method:: object.__cmp__(self, other)
1344
1360
 
1426
1442
 
1427
1443
   .. index:: builtin: unicode
1428
1444
 
1429
 
   Called to implement :func:`unicode` builtin; should return a Unicode object.
 
1445
   Called to implement :func:`unicode` built-in; should return a Unicode object.
1430
1446
   When this method is not defined, string conversion is attempted, and the result
1431
1447
   of string conversion is converted to Unicode using the system default encoding.
1432
1448
 
1505
1521
   .. note::
1506
1522
 
1507
1523
      This method may still be bypassed when looking up special methods as the
1508
 
      result of implicit invocation via language syntax or builtin functions.
 
1524
      result of implicit invocation via language syntax or built-in functions.
1509
1525
      See :ref:`new-style-special-lookup`.
1510
1526
 
1511
1527
 
1659
1675
  *__slots__*; otherwise, the class attribute would overwrite the descriptor
1660
1676
  assignment.
1661
1677
 
 
1678
* The action of a *__slots__* declaration is limited to the class where it is
 
1679
  defined.  As a result, subclasses will have a *__dict__* unless they also define
 
1680
  *__slots__* (which must only contain names of any *additional* slots).
 
1681
 
1662
1682
* If a class defines a slot also defined in a base class, the instance variable
1663
1683
  defined by the base class slot is inaccessible (except by retrieving its
1664
1684
  descriptor directly from the base class). This renders the meaning of the
1665
1685
  program undefined.  In the future, a check may be added to prevent this.
1666
1686
 
1667
 
* The action of a *__slots__* declaration is limited to the class where it is
1668
 
  defined.  As a result, subclasses will have a *__dict__* unless they also define
1669
 
  *__slots__*.
1670
 
 
1671
1687
* Nonempty *__slots__* does not work for classes derived from "variable-length"
1672
1688
  built-in types such as :class:`long`, :class:`str` and :class:`tuple`.
1673
1689
 
1854
1870
 
1855
1871
.. method:: object.__reversed__(self)
1856
1872
 
1857
 
   Called (if present) by the :func:`reversed` builtin to implement
 
1873
   Called (if present) by the :func:`reversed` built-in to implement
1858
1874
   reverse iteration.  It should return a new iterator object that iterates
1859
1875
   over all the objects in the container in reverse order.
1860
1876
 
1861
1877
   If the :meth:`__reversed__` method is not provided, the :func:`reversed`
1862
 
   builtin will fall back to using the sequence protocol (:meth:`__len__` and
 
1878
   built-in will fall back to using the sequence protocol (:meth:`__len__` and
1863
1879
   :meth:`__getitem__`).  Objects that support the sequence protocol should
1864
1880
   only provide :meth:`__reversed__` if they can provide an implementation
1865
1881
   that is more efficient than the one provided by :func:`reversed`.
1872
1888
supply the following special method with a more efficient implementation, which
1873
1889
also does not require the object be a sequence.
1874
1890
 
1875
 
 
1876
1891
.. method:: object.__contains__(self, item)
1877
1892
 
1878
 
   Called to implement membership test operators.  Should return true if *item* is
1879
 
   in *self*, false otherwise.  For mapping objects, this should consider the keys
1880
 
   of the mapping rather than the values or the key-item pairs.
 
1893
   Called to implement membership test operators.  Should return true if *item*
 
1894
   is in *self*, false otherwise.  For mapping objects, this should consider the
 
1895
   keys of the mapping rather than the values or the key-item pairs.
 
1896
 
 
1897
   For objects that don't define :meth:`__contains__`, the membership test first
 
1898
   tries iteration via :meth:`__iter__`, then the old sequence iteration
 
1899
   protocol via :meth:`__getitem__`, see :ref:`this section in the language
 
1900
   reference <membership-test-details>`.
1881
1901
 
1882
1902
 
1883
1903
.. _sequence-methods: