mirror of https://github.com/python/cpython.git
Work around the conversion of ">>" and "<<" to guillemets. Reported by Ping.
Wrap some long lines and fix some markup nits.
This commit is contained in:
parent
d9994e0115
commit
fb8ffe6b5e
107
Doc/ref/ref3.tex
107
Doc/ref/ref3.tex
|
@ -1233,22 +1233,24 @@ object is created instead, and passed to \method{__getitem__()} instead.
|
||||||
Called to implement assignment to \code{\var{self}[\var{i}:\var{j}]}.
|
Called to implement assignment to \code{\var{self}[\var{i}:\var{j}]}.
|
||||||
Same notes for \var{i} and \var{j} as for \method{__getslice__()}.
|
Same notes for \var{i} and \var{j} as for \method{__getslice__()}.
|
||||||
|
|
||||||
This method is deprecated. If no \method{__setslice__()} is found, a slice
|
This method is deprecated. If no \method{__setslice__()} is found, a
|
||||||
object is created instead, and passed to \method{__setitem__()} instead.
|
slice object is created instead, and passed to \method{__setitem__()}
|
||||||
|
instead.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[sequence object]{__delslice__}{self, i, j}
|
\begin{methoddesc}[sequence object]{__delslice__}{self, i, j}
|
||||||
Called to implement deletion of \code{\var{self}[\var{i}:\var{j}]}.
|
Called to implement deletion of \code{\var{self}[\var{i}:\var{j}]}.
|
||||||
Same notes for \var{i} and \var{j} as for \method{__getslice__()}.
|
Same notes for \var{i} and \var{j} as for \method{__getslice__()}.
|
||||||
This method is deprecated. If no \method{__delslice__()} is found, a slice
|
This method is deprecated. If no \method{__delslice__()} is found, a
|
||||||
object is created instead, and passed to \method{__delitem__()} instead.
|
slice object is created instead, and passed to \method{__delitem__()}
|
||||||
|
instead.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
Notice that these methods are only invoked when a single slice with a single
|
Notice that these methods are only invoked when a single slice with a
|
||||||
colon is used, and the slice method is available. For slice operations
|
single colon is used, and the slice method is available. For slice
|
||||||
involving extended slice notation, or in absence of the slice methods,
|
operations involving extended slice notation, or in absence of the
|
||||||
\method{__getitem__()}, \method{__setitem__()} or \method{__delitem__()} is
|
slice methods, \method{__getitem__()}, \method{__setitem__()} or
|
||||||
called with a slice object as argument.
|
\method{__delitem__()} is called with a slice object as argument.
|
||||||
|
|
||||||
The following example demonstrate how to make your program or module
|
The following example demonstrate how to make your program or module
|
||||||
compatible with earlier versions of Python (assuming that methods
|
compatible with earlier versions of Python (assuming that methods
|
||||||
|
@ -1326,10 +1328,10 @@ These functions are
|
||||||
called to implement the binary arithmetic operations (\code{+},
|
called to implement the binary arithmetic operations (\code{+},
|
||||||
\code{-}, \code{*}, \code{/}, \code{\%},
|
\code{-}, \code{*}, \code{/}, \code{\%},
|
||||||
\function{divmod()}\bifuncindex{divmod},
|
\function{divmod()}\bifuncindex{divmod},
|
||||||
\function{pow()}\bifuncindex{pow}, \code{**}, \code{<<}, \code{>>},
|
\function{pow()}\bifuncindex{pow}, \code{**}, \code{<}\code{<},
|
||||||
\code{\&}, \code{\^}, \code{|}). For instance, to evaluate the
|
\code{>}\code{>}, \code{\&}, \code{\^}, \code{|}). For instance, to
|
||||||
expression \var{x}\code{+}\var{y}, where \var{x} is an instance of a
|
evaluate the expression \var{x}\code{+}\var{y}, where \var{x} is an
|
||||||
class that has an \method{__add__()} method,
|
instance of a class that has an \method{__add__()} method,
|
||||||
\code{\var{x}.__add__(\var{y})} is called. Note that
|
\code{\var{x}.__add__(\var{y})} is called. Note that
|
||||||
\method{__pow__()} should be defined to accept an optional third
|
\method{__pow__()} should be defined to accept an optional third
|
||||||
argument if the ternary version of the built-in
|
argument if the ternary version of the built-in
|
||||||
|
@ -1352,14 +1354,15 @@ These functions are
|
||||||
called to implement the binary arithmetic operations (\code{+},
|
called to implement the binary arithmetic operations (\code{+},
|
||||||
\code{-}, \code{*}, \code{/}, \code{\%},
|
\code{-}, \code{*}, \code{/}, \code{\%},
|
||||||
\function{divmod()}\bifuncindex{divmod},
|
\function{divmod()}\bifuncindex{divmod},
|
||||||
\function{pow()}\bifuncindex{pow}, \code{**}, \code{<<}, \code{>>},
|
\function{pow()}\bifuncindex{pow}, \code{**}, \code{<}\code{<},
|
||||||
\code{\&}, \code{\^}, \code{|}) with reflected (swapped) operands. These
|
\code{>}\code{>}, \code{\&}, \code{\^}, \code{|}) with reflected
|
||||||
functions are only called if the left operand does not support the
|
(swapped) operands. These functions are only called if the left
|
||||||
corresponding operation. For instance, to evaluate the expression
|
operand does not support the corresponding operation. For instance,
|
||||||
\var{x}\code{-}\var{y}, where \var{y} is an instance of a class that
|
to evaluate the expression \var{x}\code{-}\var{y}, where \var{y} is an
|
||||||
has an \method{__rsub__()} method, \code{\var{y}.__rsub__(\var{x})} is
|
instance of a class that has an \method{__rsub__()} method,
|
||||||
called. Note that ternary \function{pow()}\bifuncindex{pow} will not
|
\code{\var{y}.__rsub__(\var{x})} is called. Note that ternary
|
||||||
try calling \method{__rpow__()} (the coercion rules would become too
|
\function{pow()}\bifuncindex{pow} will not try calling
|
||||||
|
\method{__rpow__()} (the coercion rules would become too
|
||||||
complicated).
|
complicated).
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
|
@ -1374,27 +1377,28 @@ complicated).
|
||||||
\methodline[numeric object]{__iand__}{self, other}
|
\methodline[numeric object]{__iand__}{self, other}
|
||||||
\methodline[numeric object]{__ixor__}{self, other}
|
\methodline[numeric object]{__ixor__}{self, other}
|
||||||
\methodline[numeric object]{__ior__}{self, other}
|
\methodline[numeric object]{__ior__}{self, other}
|
||||||
These methods are called to implement the augmented arithmetic operations
|
These methods are called to implement the augmented arithmetic
|
||||||
(\code{+=}, \code{-=}, \code{*=}, \code{/=}, \code{\%=}, \code{**=},
|
operations (\code{+=}, \code{-=}, \code{*=}, \code{/=}, \code{\%=},
|
||||||
\code{<<=}, \code{>>=}, \code{\&=}, \code{\^=}, \code{|=}). These methods
|
\code{**=}, \code{<}\code{<=}, \code{>}\code{>=}, \code{\&=},
|
||||||
should attempt to do the operation in-place (modifying \var{self}) and
|
\code{\^=}, \code{|=}). These methods should attempt to do the
|
||||||
return the result (which could be, but does not have to be, \var{self}). If
|
operation in-place (modifying \var{self}) and return the result (which
|
||||||
a specific method is not defined, the augmented operation falls back to the
|
could be, but does not have to be, \var{self}). If a specific method
|
||||||
normal methods. For instance, to evaluate the expression
|
is not defined, the augmented operation falls back to the normal
|
||||||
\var{x}\code{+=}\var{y}, where \var{x} is an instance of a class that has an
|
methods. For instance, to evaluate the expression
|
||||||
\method{__iadd__()} method, \code{\var{x}.__iadd__(\var{y})} is called. If
|
\var{x}\code{+=}\var{y}, where \var{x} is an instance of a class that
|
||||||
\var{x} is an instance of a class that does not define a \method{__iadd()}
|
has an \method{__iadd__()} method, \code{\var{x}.__iadd__(\var{y})} is
|
||||||
method, \code{\var{x}.__add__(\var{y})} and \code{\var{y}.__radd__(\var{x})}
|
called. If \var{x} is an instance of a class that does not define a
|
||||||
are considered, as with the evaluation of \var{x}\code{+}\var{y}.
|
\method{__iadd()} method, \code{\var{x}.__add__(\var{y})} and
|
||||||
|
\code{\var{y}.__radd__(\var{x})} are considered, as with the
|
||||||
|
evaluation of \var{x}\code{+}\var{y}.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[numeric object]{__neg__}{self}
|
\begin{methoddesc}[numeric object]{__neg__}{self}
|
||||||
\methodline[numeric object]{__pos__}{self}
|
\methodline[numeric object]{__pos__}{self}
|
||||||
\methodline[numeric object]{__abs__}{self}
|
\methodline[numeric object]{__abs__}{self}
|
||||||
\methodline[numeric object]{__invert__}{self}
|
\methodline[numeric object]{__invert__}{self}
|
||||||
Called to implement the unary arithmetic operations (\code{-}, \code{+},
|
Called to implement the unary arithmetic operations (\code{-},
|
||||||
\function{abs()}\bifuncindex{abs} and \code{\~{}}).
|
\code{+}, \function{abs()}\bifuncindex{abs} and \code{\~{}}).
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[numeric object]{__complex__}{self}
|
\begin{methoddesc}[numeric object]{__complex__}{self}
|
||||||
|
@ -1427,17 +1431,17 @@ the other type here).
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\strong{Coercion rules}: to evaluate \var{x} \var{op} \var{y}, the
|
\strong{Coercion rules}: to evaluate \var{x} \var{op} \var{y}, the
|
||||||
following steps are taken (where \method{__op__()} and
|
following steps are taken (where \method{__\var{op}__()} and
|
||||||
\method{__rop__()} are the method names corresponding to \var{op},
|
\method{__r\var{op}__()} are the method names corresponding to
|
||||||
e.g., if var{op} is `\code{+}', \method{__add__()} and
|
\var{op}, e.g., if \var{op} is `\code{+}', \method{__add__()} and
|
||||||
\method{__radd__()} are used). If an exception occurs at any point,
|
\method{__radd__()} are used). If an exception occurs at any point,
|
||||||
the evaluation is abandoned and exception handling takes over.
|
the evaluation is abandoned and exception handling takes over.
|
||||||
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
|
|
||||||
\item[0.] If \var{x} is a string object and op is the modulo operator (\%),
|
\item[0.] If \var{x} is a string object and \var{op} is the modulo
|
||||||
the string formatting operation is invoked and the remaining steps are
|
operator (\%), the string formatting operation is invoked and
|
||||||
skipped.
|
the remaining steps are skipped.
|
||||||
|
|
||||||
\item[1.] If \var{x} is a class instance:
|
\item[1.] If \var{x} is a class instance:
|
||||||
|
|
||||||
|
@ -1451,8 +1455,8 @@ skipped.
|
||||||
\item[1b.] If neither \var{x} nor \var{y} is a class instance
|
\item[1b.] If neither \var{x} nor \var{y} is a class instance
|
||||||
after coercion, go to step 3.
|
after coercion, go to step 3.
|
||||||
|
|
||||||
\item[1c.] If \var{x} has a method \method{__op__()}, return
|
\item[1c.] If \var{x} has a method \method{__\var{op}__()}, return
|
||||||
\code{\var{x}.__op__(\var{y})}; otherwise, restore \var{x} and
|
\code{\var{x}.__\var{op}__(\var{y})}; otherwise, restore \var{x} and
|
||||||
\var{y} to their value before step 1a.
|
\var{y} to their value before step 1a.
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
@ -1469,9 +1473,9 @@ skipped.
|
||||||
\item[2b.] If neither \var{x} nor \var{y} is a class instance
|
\item[2b.] If neither \var{x} nor \var{y} is a class instance
|
||||||
after coercion, go to step 3.
|
after coercion, go to step 3.
|
||||||
|
|
||||||
\item[2b.] If \var{y} has a method \method{__rop__()}, return
|
\item[2b.] If \var{y} has a method \method{__r\var{op}__()},
|
||||||
\code{\var{y}.__rop__(\var{x})}; otherwise, restore \var{x}
|
return \code{\var{y}.__r\var{op}__(\var{x})}; otherwise,
|
||||||
and \var{y} to their value before step 2a.
|
restore \var{x} and \var{y} to their value before step 2a.
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
|
@ -1480,11 +1484,12 @@ instance.
|
||||||
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
|
|
||||||
\item[3a.] If op is `\code{+}' and \var{x} is a sequence,
|
\item[3a.] If \var{op} is `\code{+}' and \var{x} is a
|
||||||
sequence concatenation is invoked.
|
sequence, sequence concatenation is invoked.
|
||||||
|
|
||||||
\item[3b.] If op is `\code{*}' and one operand is a sequence
|
\item[3b.] If \var{op} is `\code{*}' and one operand is a
|
||||||
and the other an integer, sequence repetition is invoked.
|
sequence and the other an integer, sequence repetition is
|
||||||
|
invoked.
|
||||||
|
|
||||||
\item[3c.] Otherwise, both operands must be numbers; they are
|
\item[3c.] Otherwise, both operands must be numbers; they are
|
||||||
coerced to a common type if possible, and the numeric
|
coerced to a common type if possible, and the numeric
|
||||||
|
|
Loading…
Reference in New Issue