summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/compound_stmts.rst6
-rw-r--r--Doc/reference/datamodel.rst63
-rw-r--r--Doc/reference/expressions.rst7
-rw-r--r--Doc/reference/lexical_analysis.rst3
-rw-r--r--Doc/reference/simple_stmts.rst20
5 files changed, 75 insertions, 24 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 432f3c8..927930a 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -72,6 +72,8 @@ on a separate line for clarity.
.. _if:
+.. _elif:
+.. _else:
The :keyword:`if` statement
===========================
@@ -200,6 +202,8 @@ returns the list ``[0, 1, 2]``.
.. _try:
+.. _except:
+.. _finally:
The :keyword:`try` statement
============================
@@ -326,6 +330,7 @@ may be found in section :ref:`raise`.
.. _with:
+.. _as:
The :keyword:`with` statement
=============================
@@ -382,6 +387,7 @@ The execution of the :keyword:`with` statement proceeds as follows:
.. _function:
+.. _def:
Function definitions
====================
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 49bc8b6..0ec255f 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -202,8 +202,6 @@ Numbers
operation except left shift, if it yields a result in the plain integer domain
without causing overflow, will yield the same result when using mixed operands.
- .. % Integers
-
Floating point numbers
.. index::
object: floating point
@@ -229,8 +227,6 @@ Numbers
The real and imaginary parts of a complex number ``z`` can be retrieved through
the read-only attributes ``z.real`` and ``z.imag``.
- .. % Numbers
-
Sequences
.. index::
builtin: len
@@ -302,8 +298,6 @@ Sequences
parentheses must be usable for grouping of expressions). An empty
tuple can be formed by an empty pair of parentheses.
- .. % Immutable sequences
-
Mutable sequences
.. index::
object: mutable sequence
@@ -341,10 +335,6 @@ Sequences
The extension module :mod:`array` provides an additional example of a
mutable sequence type.
- .. % Mutable sequences
-
- .. % Sequences
-
Set types
.. index::
builtin: len
@@ -379,8 +369,6 @@ Set types
:term:`hashable`, it can be used again as an element of another set, or as
a dictionary key.
- .. % Set types
-
Mappings
.. index::
builtin: len
@@ -418,8 +406,6 @@ Mappings
The extension modules :mod:`dbm`, :mod:`gdbm`, and :mod:`bsddb` provide
additional examples of mapping types.
- .. % Mapping types
-
Callable types
.. index::
object: callable
@@ -652,8 +638,6 @@ Modules
object used to initialize the module (since it isn't needed once the
initialization is done).
- .. %
-
Attribute assignment updates the module's namespace dictionary, e.g., ``m.x =
1`` is equivalent to ``m.__dict__["x"] = 1``.
@@ -992,12 +976,53 @@ Internal types
described above, under "User-defined methods". Class method objects are created
by the built-in :func:`classmethod` constructor.
- .. % Internal types
-
-.. % =========================================================================
.. _newstyle:
+New-style and classic classes
+=============================
+
+Classes and instances come in two flavors: old-style or classic, and new-style.
+
+Up to Python 2.1, old-style classes were the only flavour available to the user.
+The concept of (old-style) class is unrelated to the concept of type: if *x* is
+an instance of an old-style class, then ``x.__class__`` designates the class of
+*x*, but ``type(x)`` is always ``<type 'instance'>``. This reflects the fact
+that all old-style instances, independently of their class, are implemented with
+a single built-in type, called ``instance``.
+
+New-style classes were introduced in Python 2.2 to unify classes and types. A
+new-style class neither more nor less than a user-defined type. If *x* is an
+instance of a new-style class, then ``type(x)`` is the same as ``x.__class__``.
+
+The major motivation for introducing new-style classes is to provide a unified
+object model with a full meta-model. It also has a number of immediate
+benefits, like the ability to subclass most built-in types, or the introduction
+of "descriptors", which enable computed properties.
+
+For compatibility reasons, classes are still old-style by default. New-style
+classes are created by specifying another new-style class (i.e. a type) as a
+parent class, or the "top-level type" :class:`object` if no other parent is
+needed. The behaviour of new-style classes differs from that of old-style
+classes in a number of important details in addition to what :func:`type`
+returns. Some of these changes are fundamental to the new object model, like
+the way special methods are invoked. Others are "fixes" that could not be
+implemented before for compatibility concerns, like the method resolution order
+in case of multiple inheritance.
+
+This manual is not up-to-date with respect to new-style classes. For now,
+please see http://www.python.org/doc/newstyle.html for more information.
+
+.. index::
+ single: class
+ single: class
+ single: class
+
+The plan is to eventually drop old-style classes, leaving only the semantics of
+new-style classes. This change will probably only be feasible in Python 3.0.
+new-style classic old-style
+
+
.. _specialnames:
Special method names
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 4bb0074..6e160ee 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -937,6 +937,10 @@ must be integers.
.. _comparisons:
+.. _is:
+.. _isnot:
+.. _in:
+.. _notin:
Comparisons
===========
@@ -1058,6 +1062,9 @@ yields the inverse truth value.
.. _booleans:
+.. _and:
+.. _or:
+.. _not:
Boolean operations
==================
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst
index 741f8ec..ae71ec7 100644
--- a/Doc/reference/lexical_analysis.rst
+++ b/Doc/reference/lexical_analysis.rst
@@ -100,8 +100,7 @@ If an encoding is declared, the encoding name must be recognized by Python. The
encoding is used for all lexical analysis, including string literals, comments
and identifiers. The encoding declaration must appear on a line of its own.
-A list of standard encodings can be found in the section
-:ref:`standard-encodings`.
+.. XXX there should be a list of supported encodings.
.. _explicit-joining:
diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst
index e9be1fd..a822006 100644
--- a/Doc/reference/simple_stmts.rst
+++ b/Doc/reference/simple_stmts.rst
@@ -143,6 +143,19 @@ Assignment of an object to a single target is recursively defined as follows.
count for the object previously bound to the name to reach zero, causing the
object to be deallocated and its destructor (if it has one) to be called.
+ .. index:: single: destructor
+
+ The name is rebound if it was already bound. This may cause the reference count
+ for the object previously bound to the name to reach zero, causing the object to
+ be deallocated and its destructor (if it has one) to be called.
+
+* If the target is a target list enclosed in parentheses or in square brackets:
+ The object must be a sequence with the same number of items as there are targets
+ in the target list, and its items are assigned, from left to right, to the
+ corresponding targets.
+
+ .. index:: pair: attribute; assignment
+
* If the target is an attribute reference: The primary expression in the
reference is evaluated. It should yield an object with assignable attributes;
if this is not the case, :exc:`TypeError` is raised. That object is then
@@ -296,16 +309,16 @@ The extended form, ``assert expression1, expression2``, is equivalent to ::
single: __debug__
exception: AssertionError
-These equivalences assume that ``__debug__`` and :exc:`AssertionError` refer to
+These equivalences assume that :const:`__debug__` and :exc:`AssertionError` refer to
the built-in variables with those names. In the current implementation, the
-built-in variable ``__debug__`` is ``True`` under normal circumstances,
+built-in variable :const:`__debug__` is ``True`` under normal circumstances,
``False`` when optimization is requested (command line option -O). The current
code generator emits no code for an assert statement when optimization is
requested at compile time. Note that it is unnecessary to include the source
code for the expression that failed in the error message; it will be displayed
as part of the stack trace.
-Assignments to ``__debug__`` are illegal. The value for the built-in variable
+Assignments to :const:`__debug__` are illegal. The value for the built-in variable
is determined when the interpreter starts.
@@ -512,6 +525,7 @@ cycle of the nearest enclosing loop.
.. _import:
+.. _from:
The :keyword:`import` statement
===============================