summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-06 08:26:09 (GMT)
committerGeorg Brandl <georg@python.org>2010-10-06 08:26:09 (GMT)
commit4009c9edfc18a37ea0be473542a30c7c858155e0 (patch)
tree007572c30f110d05f730a7169972b534cb2010e5 /Doc/reference
parent914a218fbe6d970059b4683d73a449cbc6cf5bf3 (diff)
downloadcpython-4009c9edfc18a37ea0be473542a30c7c858155e0.zip
cpython-4009c9edfc18a37ea0be473542a30c7c858155e0.tar.gz
cpython-4009c9edfc18a37ea0be473542a30c7c858155e0.tar.bz2
Merged revisions 82805-82806,83523-83527,83536,83538,83542,83546-83548,83550-83555,83558,83560 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k ........ r82805 | georg.brandl | 2010-07-11 11:42:10 +0200 (So, 11 Jul 2010) | 1 line #7935: cross-reference to ast.literal_eval() from eval() docs. ........ r82806 | georg.brandl | 2010-07-11 12:22:44 +0200 (So, 11 Jul 2010) | 1 line #9223: link to Command class reference, and move Command interface docs nearer to class docs. ........ r83523 | georg.brandl | 2010-08-02 14:06:18 +0200 (Mo, 02 Aug 2010) | 1 line #9209 and #7781: fix two crashes in pstats interactive browser. ........ r83524 | georg.brandl | 2010-08-02 14:20:23 +0200 (Mo, 02 Aug 2010) | 1 line #9428: fix running scripts from profile/cProfile with their own name and the right namespace. Same fix as for trace.py in #1690103. ........ r83525 | georg.brandl | 2010-08-02 14:36:24 +0200 (Mo, 02 Aug 2010) | 1 line Get rid of spurious "threading" entries in trace output. ........ r83526 | georg.brandl | 2010-08-02 14:40:22 +0200 (Mo, 02 Aug 2010) | 1 line Fix softspace relic. ........ r83527 | georg.brandl | 2010-08-02 14:48:46 +0200 (Mo, 02 Aug 2010) | 1 line #3821: beginnings of a trace.py unittest. ........ r83536 | georg.brandl | 2010-08-02 19:49:25 +0200 (Mo, 02 Aug 2010) | 1 line #8578: mention danger of not incref'ing weak referenced object. ........ r83538 | georg.brandl | 2010-08-02 20:10:13 +0200 (Mo, 02 Aug 2010) | 1 line #6928: fix class docs w.r.t. new metaclasses. ........ r83542 | georg.brandl | 2010-08-02 20:56:54 +0200 (Mo, 02 Aug 2010) | 1 line Move test_SimpleHTTPServer into test_httpservers. ........ r83546 | georg.brandl | 2010-08-02 21:16:34 +0200 (Mo, 02 Aug 2010) | 1 line #7973: Fix distutils options spelling. ........ r83547 | georg.brandl | 2010-08-02 21:19:26 +0200 (Mo, 02 Aug 2010) | 1 line #7386: add example that shows that trailing path separators are stripped. ........ r83548 | georg.brandl | 2010-08-02 21:23:34 +0200 (Mo, 02 Aug 2010) | 1 line #8172: how does one use a property? ........ r83550 | georg.brandl | 2010-08-02 21:32:43 +0200 (Mo, 02 Aug 2010) | 1 line #9451: strengthen warning about __*__ special name usage. ........ r83551 | georg.brandl | 2010-08-02 21:35:06 +0200 (Mo, 02 Aug 2010) | 1 line Remove XXX comment that was displayed. ........ r83552 | georg.brandl | 2010-08-02 21:36:36 +0200 (Mo, 02 Aug 2010) | 1 line #9438: clarify that constant names also cannot be assigned as attributes. ........ r83553 | georg.brandl | 2010-08-02 21:39:17 +0200 (Mo, 02 Aug 2010) | 1 line Remove redundant information. ........ r83554 | georg.brandl | 2010-08-02 21:43:05 +0200 (Mo, 02 Aug 2010) | 1 line #7280: note about nasmw.exe. ........ r83555 | georg.brandl | 2010-08-02 21:44:48 +0200 (Mo, 02 Aug 2010) | 1 line #8861: remove unused variable. ........ r83558 | georg.brandl | 2010-08-02 22:05:19 +0200 (Mo, 02 Aug 2010) | 1 line #8648: document UTF-7 codec functions. ........ r83560 | georg.brandl | 2010-08-02 22:16:18 +0200 (Mo, 02 Aug 2010) | 1 line #9087: update json docstrings -- unicode and long do not exist anymore. ........
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/compound_stmts.rst50
-rw-r--r--Doc/reference/lexical_analysis.rst11
2 files changed, 30 insertions, 31 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 9bcb108..e2db33c 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -550,24 +550,27 @@ Class definitions
A class definition defines a class object (see section :ref:`types`):
-.. XXX need to document PEP 3115 changes here (new metaclasses)
-
.. productionlist::
classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite`
- inheritance: "(" [`expression_list`] ")"
+ inheritance: "(" [`argument_list` [","] ] ")"
classname: `identifier`
-A class definition is an executable statement. It first evaluates the
-inheritance list, if present. Each item in the inheritance list should evaluate
-to a class object or class type which allows subclassing. The class's suite is
-then executed in a new execution frame (see section :ref:`naming`), using a
-newly created local namespace and the original global namespace. (Usually, the
-suite contains only function definitions.) When the class's suite finishes
-execution, its execution frame is discarded but its local namespace is
-saved. [#]_ A class object is then created using the inheritance list for the
-base classes and the saved local namespace for the attribute dictionary. The
-class name is bound to this class object in the original local namespace.
+A class definition is an executable statement. The inheritance list usually
+gives a list of base classes (see :ref:`metaclasses` for more advanced uses), so
+each item in the list should evaluate to a class object which allows
+subclassing.
+
+The class's suite is then executed in a new execution frame (see :ref:`naming`),
+using a newly created local namespace and the original global namespace.
+(Usually, the suite contains mostly function definitions.) When the class's
+suite finishes execution, its execution frame is discarded but its local
+namespace is saved. [#]_ A class object is then created using the inheritance
+list for the base classes and the saved local namespace for the attribute
+dictionary. The class name is bound to this class object in the original local
+namespace.
+
+Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
Classes can also be decorated; as with functions, ::
@@ -581,25 +584,20 @@ is equivalent to ::
Foo = f1(arg)(f2(Foo))
**Programmer's note:** Variables defined in the class definition are class
-variables; they are shared by instances. Instance variables can be set in a
-method with ``self.name = value``. Both class and instance variables are
-accessible through the notation "``self.name``", and an instance variable hides
-a class variable with the same name when accessed in this way. Class variables
-can be used as defaults for instance variables, but using mutable values there
-can lead to unexpected results. Descriptors can be used to create instance
-variables with different implementation details.
+attributes; they are shared by instances. Instance attributes can be set in a
+method with ``self.name = value``. Both class and instance attributes are
+accessible through the notation "``self.name``", and an instance attribute hides
+a class attribute with the same name when accessed in this way. Class
+attributes can be used as defaults for instance attributes, but using mutable
+values there can lead to unexpected results. :ref:`Descriptors <descriptors>`
+can be used to create instance variables with different implementation details.
-.. XXX add link to descriptor docs above
.. seealso::
+ :pep:`3116` - Metaclasses in Python 3
:pep:`3129` - Class Decorators
-Class definitions, like function definitions, may be wrapped by one or more
-:term:`decorator` expressions. The evaluation rules for the decorator
-expressions are the same as for functions. The result must be a class object,
-which is then bound to the class name.
-
.. rubric:: Footnotes
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst
index 1b8b7b5..51a291e 100644
--- a/Doc/reference/lexical_analysis.rst
+++ b/Doc/reference/lexical_analysis.rst
@@ -362,11 +362,12 @@ characters:
information on this convention.
``__*__``
- System-defined names. These names are defined by the interpreter and its
- implementation (including the standard library); applications should not expect
- to define additional names using this convention. The set of names of this
- class defined by Python may be extended in future versions. See section
- :ref:`specialnames`.
+ System-defined names. These names are defined by the interpreter and its
+ implementation (including the standard library). Current system names are
+ discussed in the :ref:`specialnames` section and elsewhere. More will likely
+ be defined in future versions of Python. *Any* use of ``__*__`` names, in
+ any context, that does not follow explicitly documented use, is subject to
+ breakage without warning.
``__*``
Class-private names. Names in this category, when used within the context of a