Index: Doc/reference/compound_stmts.rst =================================================================== --- Doc/reference/compound_stmts.rst (revision 82356) +++ Doc/reference/compound_stmts.rst (working copy) @@ -555,13 +555,17 @@ .. XXX need to document PEP 3115 changes here (new metaclasses) .. productionlist:: - classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite` - inheritance: "(" [`expression_list`] ")" + classdef: [`decorators`] "class" `classname` + : ["(" [`argument_list` [","] | `comprehension`] ")"] + : ":" `suite` classname: `identifier` +Simple class definitions +------------------------ + A class definition is an executable statement. It first evaluates the -inheritance list, if present. Each item in the inheritance list should evaluate +argument list, if present. Each item in the argument 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 @@ -571,8 +575,28 @@ 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. -Classes can also be decorated; as with functions, :: +**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. + +Complex class definitions, and metaclasses +------------------------------------------ + +See :pep:`3115` for information on metaclasses. + + +Class decorators +---------------- + +Class definitions, like function definitions, may also be wrapped by +one of more :term:`decorator` expressions:: + @f1(arg) @f2 class Foo: pass @@ -582,25 +606,15 @@ class Foo: pass 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. +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. -.. XXX add link to descriptor docs above - .. seealso:: :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. +.. XXX add link to descriptor docs above .. rubric:: Footnotes