diff options
author | Georg Brandl <georg@python.org> | 2010-10-17 10:38:20 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-10-17 10:38:20 (GMT) |
commit | f41427263c5e34e3746d6ad9d48d6caa90bdaaed (patch) | |
tree | ca41fd6b6f111dab5a9dc88e448d8be9bbd0ba1f /Doc/reference/compound_stmts.rst | |
parent | e0bf91d59753de2aba91b4255a21921251d0d26a (diff) | |
download | cpython-f41427263c5e34e3746d6ad9d48d6caa90bdaaed.zip cpython-f41427263c5e34e3746d6ad9d48d6caa90bdaaed.tar.gz cpython-f41427263c5e34e3746d6ad9d48d6caa90bdaaed.tar.bz2 |
#9117: fix syntax for class definition.
Diffstat (limited to 'Doc/reference/compound_stmts.rst')
-rw-r--r-- | Doc/reference/compound_stmts.rst | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 4e6086f..95d5705 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -555,10 +555,9 @@ A class definition defines a class object (see section :ref:`types`): .. productionlist:: classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite` - inheritance: "(" [`argument_list` [","] ] ")" + inheritance: "(" [`argument_list` [","] | `comprehension`] ")" classname: `identifier` - 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 @@ -575,7 +574,7 @@ namespace. Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`. -Classes can also be decorated; as with functions, :: +Classes can also be decorated: just like when decorating functions, :: @f1(arg) @f2 @@ -586,6 +585,10 @@ is equivalent to :: class Foo: pass Foo = f1(arg)(f2(Foo)) +The evaluation rules for the decorator expressions are the same as for function +decorators. The result must be a class object, which is then bound to the class +name. + **Programmer's note:** Variables defined in the class definition are class attributes; they are shared by instances. Instance attributes can be set in a method with ``self.name = value``. Both class and instance attributes are |