diff options
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/datamodel.rst | 16 | ||||
-rw-r--r-- | Doc/reference/expressions.rst | 12 |
2 files changed, 19 insertions, 9 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 2f6013e..baa6eaa 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1544,11 +1544,11 @@ Super Binding ``A.__dict__['m'].__get__(obj, A)``. For instance bindings, the precedence of descriptor invocation depends on the -which descriptor methods are defined. Data descriptors define both -:meth:`__get__` and :meth:`__set__`. Non-data descriptors have just the +which descriptor methods are defined. Normally, data descriptors define both +:meth:`__get__` and :meth:`__set__`, while non-data descriptors have just the :meth:`__get__` method. Data descriptors always override a redefinition in an instance dictionary. In contrast, non-data descriptors can be overridden by -instances. +instances. [#]_ Python methods (including :func:`staticmethod` and :func:`classmethod`) are implemented as non-data descriptors. Accordingly, instances can redefine and @@ -1817,6 +1817,9 @@ objects. Immutable sequences methods should at most only define .. deprecated:: 2.0 Support slice objects as parameters to the :meth:`__getitem__` method. + (However, built-in types in CPython currently still implement + :meth:`__getslice__`. Therefore, you have to override it in derived + classes when implementing slicing.) Called to implement evaluation of ``self[i:j]``. The returned object should be of the same type as *self*. Note that missing *i* or *j* in the slice @@ -2112,6 +2115,13 @@ For more information on context managers, see :ref:`typecontextmanager`. .. [#] This, and other statements, are only roughly true for instances of new-style classes. +.. [#] A descriptor can define any combination of :meth:`__get__`, + :meth:`__set__` and :meth:`__delete__`. If it does not define :meth:`__get__`, + then accessing the attribute even on an instance will return the descriptor + object itself. If the descriptor defines :meth:`__set__` and/or + :meth:`__delete__`, it is a data descriptor; if it defines neither, it is a + non-data descriptor. + .. [#] For operands of the same type, it is assumed that if the non-reflected method (such as :meth:`__add__`) fails the operation is not supported, which is why the reflected method is not called. diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 476c82d..ef71a80 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -741,7 +741,7 @@ less tightly than unary operators on its right. The syntax is: Thus, in an unparenthesized sequence of power and unary operators, the operators are evaluated from right to left (this does not constrain the evaluation order -for the operands). +for the operands): ``-1**2`` results in ``-1``. The power operator has the same semantics as the built-in :func:`pow` function, when called with two arguments: it yields its left argument raised to the power @@ -959,12 +959,12 @@ Comparisons can be chained arbitrarily, e.g., ``x < y <= z`` is equivalent to ``x < y and y <= z``, except that ``y`` is evaluated only once (but in both cases ``z`` is not evaluated at all when ``x < y`` is found to be false). -Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *opa*, *opb*, ..., -*opy* are comparison operators, then *a opa b opb c* ...*y opy z* is equivalent -to *a opa b* :keyword:`and` *b opb c* :keyword:`and` ... *y opy z*, except that -each expression is evaluated at most once. +Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*, *op2*, ..., +*opN* are comparison operators, then ``a op1 b op2 c ... y opN z`` is equivalent +to ``a op1 b and b op2 c and ... y opN z``, except that each expression is +evaluated at most once. -Note that *a opa b opb c* doesn't imply any kind of comparison between *a* and +Note that ``a op1 b op2 c`` doesn't imply any kind of comparison between *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal (though perhaps not pretty). |