@@ -980,45 +980,6 @@ Internal types
980980 by the built-in :func: `classmethod ` constructor.
981981
982982
983- .. _newstyle :
984-
985- New-style and classic classes
986- =============================
987-
988- Classes and instances come in two flavors: old-style or classic, and new-style.
989-
990- Up to Python 2.1, old-style classes were the only flavour available to the user.
991- The concept of (old-style) class is unrelated to the concept of type: if *x * is
992- an instance of an old-style class, then ``x.__class__ `` designates the class of
993- *x *, but ``type(x) `` is always ``<type 'instance'> ``. This reflects the fact
994- that all old-style instances, independently of their class, are implemented with
995- a single built-in type, called ``instance ``.
996-
997- New-style classes were introduced in Python 2.2 to unify classes and types. A
998- new-style class is neither more nor less than a user-defined type. If *x * is an
999- instance of a new-style class, then ``type(x) `` is the same as ``x.__class__ ``.
1000-
1001- The major motivation for introducing new-style classes is to provide a unified
1002- object model with a full meta-model. It also has a number of immediate
1003- benefits, like the ability to subclass most built-in types, or the introduction
1004- of "descriptors", which enable computed properties.
1005-
1006- For compatibility reasons, classes are still old-style by default. New-style
1007- classes are created by specifying another new-style class (i.e. a type) as a
1008- parent class, or the "top-level type" :class: `object ` if no other parent is
1009- needed. The behaviour of new-style classes differs from that of old-style
1010- classes in a number of important details in addition to what :func: `type `
1011- returns. Some of these changes are fundamental to the new object model, like
1012- the way special methods are invoked. Others are "fixes" that could not be
1013- implemented before for compatibility concerns, like the method resolution order
1014- in case of multiple inheritance.
1015-
1016- This manual is not up-to-date with respect to new-style classes. For now,
1017- please see http://www.python.org/doc/newstyle/ for more information.
1018-
1019- .. XXX remove old style classes from docs
1020-
1021-
1022983.. _specialnames :
1023984
1024985Special method names
@@ -1418,9 +1379,7 @@ continuing through the base classes of ``type(a)`` excluding metaclasses.
14181379However, if the looked-up value is an object defining one of the descriptor
14191380methods, then Python may override the default behavior and invoke the descriptor
14201381method instead. Where this occurs in the precedence chain depends on which
1421- descriptor methods were defined and how they were called. Note that descriptors
1422- are only invoked for new style objects or classes (ones that subclass
1423- :class: `object() ` or :class: `type() `).
1382+ descriptor methods were defined and how they were called.
14241383
14251384The starting point for descriptor invocation is a binding, ``a.x ``. How the
14261385arguments are assembled depends on ``a ``:
@@ -1477,7 +1436,7 @@ saved because *__dict__* is not created for each instance.
14771436.. data :: object.__slots__
14781437
14791438 This class variable can be assigned a string, iterable, or sequence of
1480- strings with variable names used by instances. If defined in a new-style
1439+ strings with variable names used by instances. If defined in a
14811440 class, *__slots__ * reserves space for the declared variables and prevents the
14821441 automatic creation of *__dict__ * and *__weakref__ * for each instance.
14831442
@@ -1801,7 +1760,7 @@ left undefined.
18011760 ``- ``, ``* ``, ``/ ``, ``% ``, :func: `divmod `, :func: `pow `, ``** ``, ``<< ``, ``>> ``,
18021761 ``& ``, ``^ ``, ``| ``) with reflected (swapped) operands. These functions are
18031762 only called if the left operand does not support the corresponding operation and
1804- the operands are of different types. [# ]_ For instance, to evaluate the
1763+ the operands are of different types. [# ]_ For instance, to evaluate the
18051764 expression *x*``-``*y *, where *y * is an instance of a class that has an
18061765 :meth: `__rsub__ ` method, ``y.__rsub__(x) `` is called if ``x.__sub__(y) `` returns
18071766 *NotImplemented *.
@@ -1927,18 +1886,6 @@ For more information on context managers, see :ref:`typecontextmanager`.
19271886
19281887.. rubric :: Footnotes
19291888
1930- .. [# ] Since Python 2.2, a gradual merging of types and classes has been started that
1931- makes this and a few other assertions made in this manual not 100% accurate and
1932- complete: for example, it *is * now possible in some cases to change an object's
1933- type, under certain controlled conditions. Until this manual undergoes
1934- extensive revision, it must now be taken as authoritative only regarding
1935- "classic classes", that are still the default, for compatibility purposes, in
1936- Python 2.2 and 2.3. For more information, see
1937- http://www.python.org/doc/newstyle/.
1938-
1939- .. [# ] This, and other statements, are only roughly true for instances of new-style
1940- classes.
1941-
19421889.. [# ] A descriptor can define any combination of :meth: `__get__ `,
19431890 :meth: `__set__ ` and :meth: `__delete__ `. If it does not define :meth: `__get__ `,
19441891 then accessing the attribute even on an instance will return the descriptor
@@ -1949,4 +1896,3 @@ For more information on context managers, see :ref:`typecontextmanager`.
19491896 .. [# ] For operands of the same type, it is assumed that if the non-reflected method
19501897 (such as :meth: `__add__ `) fails the operation is not supported, which is why the
19511898 reflected method is not called.
1952-
0 commit comments