summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-21 17:06:07 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-21 17:06:07 (GMT)
commit4886cc331ff158f8ede74878a436adfad205bd2d (patch)
treee9473cb0fd8449b2bdfcea9826e5c795e6ba87e2 /Doc
parent79212998a8d46712edcf7c4f3fbaefca05a7b08b (diff)
downloadcpython-4886cc331ff158f8ede74878a436adfad205bd2d.zip
cpython-4886cc331ff158f8ede74878a436adfad205bd2d.tar.gz
cpython-4886cc331ff158f8ede74878a436adfad205bd2d.tar.bz2
Get rid of most of the rest of coerce (slot is still there for now).
Diffstat (limited to 'Doc')
-rw-r--r--Doc/api/abstract.tex14
-rw-r--r--Doc/ref/ref3.tex127
-rw-r--r--Doc/tut/glossary.tex41
3 files changed, 10 insertions, 172 deletions
diff --git a/Doc/api/abstract.tex b/Doc/api/abstract.tex
index 7c742a0..f35fb63 100644
--- a/Doc/api/abstract.tex
+++ b/Doc/api/abstract.tex
@@ -654,20 +654,6 @@ determination.
statement \samp{\var{o1} |= \var{o2}}.
\end{cfuncdesc}
-\begin{cfuncdesc}{int}{PyNumber_Coerce}{PyObject **p1, PyObject **p2}
- This function takes the addresses of two variables of type
- \ctype{PyObject*}. If the objects pointed to by \code{*\var{p1}}
- and \code{*\var{p2}} have the same type, increment their reference
- count and return \code{0} (success). If the objects can be converted
- to a common numeric type, replace \code{*p1} and \code{*p2} by their
- converted value (with 'new' reference counts), and return \code{0}.
- If no conversion is possible, or if some other error occurs, return
- \code{-1} (failure) and don't increment the reference counts. The
- call \code{PyNumber_Coerce(\&o1, \&o2)} is equivalent to the Python
- statement \samp{\var{o1}, \var{o2} = coerce(\var{o1}, \var{o2})}.
- \bifuncindex{coerce}
-\end{cfuncdesc}
-
\begin{cfuncdesc}{PyObject*}{PyNumber_Int}{PyObject *o}
Returns the \var{o} converted to an integer object on success, or
\NULL{} on failure. If the argument is outside the integer range
diff --git a/Doc/ref/ref3.tex b/Doc/ref/ref3.tex
index 15fc188..f53dbe3 100644
--- a/Doc/ref/ref3.tex
+++ b/Doc/ref/ref3.tex
@@ -1645,7 +1645,7 @@ sequence types should implement addition (meaning concatenation) and
multiplication (meaning repetition) by defining the methods
\method{__add__()}, \method{__radd__()}, \method{__iadd__()},
\method{__mul__()}, \method{__rmul__()} and \method{__imul__()} described
-below; they should not define \method{__coerce__()} or other numerical
+below; they should not define other numerical
operators. It is recommended that both mappings and sequences
implement the \method{__contains__()} method to allow efficient use of
the \code{in} operator; for mappings, \code{in} should be equivalent
@@ -1689,7 +1689,7 @@ through the values.
\ttindex{__imul__()}
\ttindex{__contains__()}
\ttindex{__iter__()}}
-\withsubitem{(numeric object method)}{\ttindex{__coerce__()}}
+\withsubitem{(numeric object method)}
\begin{methoddesc}[container object]{__len__}{self}
Called to implement the built-in function
@@ -2012,129 +2012,6 @@ integer (int or long).
\versionadded{2.5}
\end{methoddesc}
-\begin{methoddesc}[numeric object]{__coerce__}{self, other}
-Called to implement ``mixed-mode'' numeric arithmetic. Should either
-return a 2-tuple containing \var{self} and \var{other} converted to
-a common numeric type, or \code{None} if conversion is impossible. When
-the common type would be the type of \code{other}, it is sufficient to
-return \code{None}, since the interpreter will also ask the other
-object to attempt a coercion (but sometimes, if the implementation of
-the other type cannot be changed, it is useful to do the conversion to
-the other type here). A return value of \code{NotImplemented} is
-equivalent to returning \code{None}.
-\end{methoddesc}
-
-\subsection{Coercion rules\label{coercion-rules}}
-
-This section used to document the rules for coercion. As the language
-has evolved, the coercion rules have become hard to document
-precisely; documenting what one version of one particular
-implementation does is undesirable. Instead, here are some informal
-guidelines regarding coercion. In Python 3.0, coercion will not be
-supported.
-
-\begin{itemize}
-
-\item
-
-If the left operand of a \% operator is a string or Unicode object, no
-coercion takes place and the string formatting operation is invoked
-instead.
-
-\item
-
-It is no longer recommended to define a coercion operation.
-Mixed-mode operations on types that don't define coercion pass the
-original arguments to the operation.
-
-\item
-
-New-style classes (those derived from \class{object}) never invoke the
-\method{__coerce__()} method in response to a binary operator; the only
-time \method{__coerce__()} is invoked is when the built-in function
-\function{coerce()} is called.
-
-\item
-
-For most intents and purposes, an operator that returns
-\code{NotImplemented} is treated the same as one that is not
-implemented at all.
-
-\item
-
-Below, \method{__op__()} and \method{__rop__()} are used to signify
-the generic method names corresponding to an operator;
-\method{__iop__()} is used for the corresponding in-place operator. For
-example, for the operator `\code{+}', \method{__add__()} and
-\method{__radd__()} are used for the left and right variant of the
-binary operator, and \method{__iadd__()} for the in-place variant.
-
-\item
-
-For objects \var{x} and \var{y}, first \code{\var{x}.__op__(\var{y})}
-is tried. If this is not implemented or returns \code{NotImplemented},
-\code{\var{y}.__rop__(\var{x})} is tried. If this is also not
-implemented or returns \code{NotImplemented}, a \exception{TypeError}
-exception is raised. But see the following exception:
-
-\item
-
-Exception to the previous item: if the left operand is an instance of
-a built-in type or a new-style class, and the right operand is an instance
-of a proper subclass of that type or class and overrides the base's
-\method{__rop__()} method, the right operand's \method{__rop__()} method
-is tried \emph{before} the left operand's \method{__op__()} method.
-
-This is done so that a subclass can completely override binary operators.
-Otherwise, the left operand's \method{__op__()} method would always
-accept the right operand: when an instance of a given class is expected,
-an instance of a subclass of that class is always acceptable.
-
-\item
-
-When either operand type defines a coercion, this coercion is called
-before that type's \method{__op__()} or \method{__rop__()} method is
-called, but no sooner. If the coercion returns an object of a
-different type for the operand whose coercion is invoked, part of the
-process is redone using the new object.
-
-\item
-
-When an in-place operator (like `\code{+=}') is used, if the left
-operand implements \method{__iop__()}, it is invoked without any
-coercion. When the operation falls back to \method{__op__()} and/or
-\method{__rop__()}, the normal coercion rules apply.
-
-\item
-
-In \var{x}\code{+}\var{y}, if \var{x} is a sequence that implements
-sequence concatenation, sequence concatenation is invoked.
-
-\item
-
-In \var{x}\code{*}\var{y}, if one operator is a sequence that
-implements sequence repetition, and the other is an integer
-(\class{int} or \class{long}), sequence repetition is invoked.
-
-\item
-
-Rich comparisons (implemented by methods \method{__eq__()} and so on)
-never use coercion. Three-way comparison (implemented by
-\method{__cmp__()}) does use coercion under the same conditions as
-other binary operations use it.
-
-\item
-
-In the current implementation, the built-in numeric types \class{int},
-\class{long} and \class{float} do not use coercion; the type
-\class{complex} however does use it. The difference can become
-apparent when subclassing these types. Over time, the type
-\class{complex} may be fixed to avoid coercion. All these types
-implement a \method{__coerce__()} method, for use by the built-in
-\function{coerce()} function.
-
-\end{itemize}
-
\subsection{With Statement Context Managers\label{context-managers}}
\versionadded{2.5}
diff --git a/Doc/tut/glossary.tex b/Doc/tut/glossary.tex
index 17cc767..738e12d 100644
--- a/Doc/tut/glossary.tex
+++ b/Doc/tut/glossary.tex
@@ -35,21 +35,6 @@ machine'' that calls the subroutines corresponding to each bytecode.
Any class which does not inherit from \class{object}. See
\emph{new-style class}.
-\index{coercion}
-\item[coercion]
-The implicit conversion of an instance of one type to another during an
-operation which involves two arguments of the same type. For example,
-{}\code{int(3.15)} converts the floating point number to the integer
-{}\code{3}, but in {}\code{3+4.5}, each argument is of a different type (one
-int, one float), and both must be converted to the same type before they can
-be added or it will raise a {}\code{TypeError}. Coercion between two
-operands can be performed with the {}\code{coerce} builtin function; thus,
-{}\code{3+4.5} is equivalent to calling {}\code{operator.add(*coerce(3,
-4.5))} and results in {}\code{operator.add(3.0, 4.5)}. Without coercion,
-all arguments of even compatible types would have to be normalized to the
-same value by the programmer, e.g., {}\code{float(3)+4.5} rather than just
-{}\code{3+4.5}.
-
\index{complex number}
\item[complex number]
An extension of the familiar real number system in which all numbers are
@@ -106,17 +91,14 @@ fast style is characterized by the presence of many \keyword{try} and
\index{__future__}
\item[__future__]
A pseudo module which programmers can use to enable new language
-features which are not compatible with the current interpreter. For
-example, the expression \code{11/4} currently evaluates to \code{2}.
-If the module in which it is executed had enabled \emph{true division}
-by executing:
+features which are not compatible with the current interpreter.
+To enable \code{new_feature}
\begin{verbatim}
-from __future__ import division
+from __future__ import new_feature
\end{verbatim}
-the expression \code{11/4} would evaluate to \code{2.75}. By
-importing the \ulink{\module{__future__}}{../lib/module-future.html}
+By importing the \ulink{\module{__future__}}{../lib/module-future.html}
module and evaluating its variables, you can see when a new feature
was first added to the language and when it will become the default:
@@ -183,17 +165,10 @@ example as a key in a dictionary.
\index{integer division}
\item[integer division]
-Mathematical division discarding any remainder. For example, the
-expression \code{11/4} currently evaluates to \code{2} in contrast
-to the \code{2.75} returned by float division. Also called
-{}\emph{floor division}. When dividing two integers the outcome will
-always be another integer (having the floor function applied to it).
-However, if one of the operands is another numeric type (such as a
-{}\class{float}), the result will be coerced (see \emph{coercion}) to
-a common type. For example, an integer divided by a float will result
-in a float value, possibly with a decimal fraction. Integer division
-can be forced by using the \code{//} operator instead of the \code{/}
-operator. See also \emph{__future__}.
+Mathematical division including any remainder. The result will always
+be a float. For example, the expression \code{11/4} evaluates to \code{2.75}.
+Integer division can be forced by using the \code{//} operator instead
+of the \code{/} operator.
\index{interactive}
\item[interactive]