@@ -552,24 +552,27 @@ Class definitions
552552
553553A class definition defines a class object (see section :ref: `types `):
554554
555- .. XXX need to document PEP 3115 changes here (new metaclasses)
556-
557555.. productionlist ::
558556 classdef: [`decorators `] "class" `classname ` [`inheritance `] ":" `suite `
559- inheritance: "(" [`expression_list ` ] ")"
557+ inheritance: "(" [`argument_list ` [","] ] ")"
560558 classname: `identifier `
561559
562560
563- A class definition is an executable statement. It first evaluates the
564- inheritance list, if present. Each item in the inheritance list should evaluate
565- to a class object or class type which allows subclassing. The class's suite is
566- then executed in a new execution frame (see section :ref: `naming `), using a
567- newly created local namespace and the original global namespace. (Usually, the
568- suite contains only function definitions.) When the class's suite finishes
569- execution, its execution frame is discarded but its local namespace is
570- saved. [# ]_ A class object is then created using the inheritance list for the
571- base classes and the saved local namespace for the attribute dictionary. The
572- class name is bound to this class object in the original local namespace.
561+ A class definition is an executable statement. The inheritance list usually
562+ gives a list of base classes (see :ref: `metaclasses ` for more advanced uses), so
563+ each item in the list should evaluate to a class object which allows
564+ subclassing.
565+
566+ The class's suite is then executed in a new execution frame (see :ref: `naming `),
567+ using a newly created local namespace and the original global namespace.
568+ (Usually, the suite contains mostly function definitions.) When the class's
569+ suite finishes execution, its execution frame is discarded but its local
570+ namespace is saved. [# ]_ A class object is then created using the inheritance
571+ list for the base classes and the saved local namespace for the attribute
572+ dictionary. The class name is bound to this class object in the original local
573+ namespace.
574+
575+ Class creation can be customized heavily using :ref: `metaclasses <metaclasses >`.
573576
574577Classes can also be decorated; as with functions, ::
575578
@@ -583,25 +586,20 @@ is equivalent to ::
583586 Foo = f1(arg)(f2(Foo))
584587
585588**Programmer's note: ** Variables defined in the class definition are class
586- variables ; they are shared by instances. Instance variables can be set in a
587- method with ``self.name = value ``. Both class and instance variables are
588- accessible through the notation "``self.name ``", and an instance variable hides
589- a class variable with the same name when accessed in this way. Class variables
590- can be used as defaults for instance variables , but using mutable values there
591- can lead to unexpected results. Descriptors can be used to create instance
592- variables with different implementation details.
589+ attributes ; they are shared by instances. Instance attributes can be set in a
590+ method with ``self.name = value ``. Both class and instance attributes are
591+ accessible through the notation "``self.name ``", and an instance attribute hides
592+ a class attribute with the same name when accessed in this way. Class
593+ attributes can be used as defaults for instance attributes , but using mutable
594+ values there can lead to unexpected results. :ref: ` Descriptors < descriptors >`
595+ can be used to create instance variables with different implementation details.
593596
594- .. XXX add link to descriptor docs above
595597
596598.. seealso ::
597599
600+ :pep: `3116 ` - Metaclasses in Python 3
598601 :pep: `3129 ` - Class Decorators
599602
600- Class definitions, like function definitions, may be wrapped by one or more
601- :term: `decorator ` expressions. The evaluation rules for the decorator
602- expressions are the same as for functions. The result must be a class object,
603- which is then bound to the class name.
604-
605603
606604.. rubric :: Footnotes
607605
0 commit comments