Skip to content

Commit 16c7075

Browse files
committed
Remove more cruft leftover from nb_coerce. Rename nb_coerce to
nb_reserved.
1 parent 8ce81f7 commit 16c7075

File tree

15 files changed

+20
-66
lines changed

15 files changed

+20
-66
lines changed

Demo/classes/Rat.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ def __rcmp__(b, a):
226226
def __bool__(a):
227227
return a.__num != 0
228228

229-
# coercion
230-
def __coerce__(a, b):
231-
return a, Rat(b)
232-
233229
def test():
234230
'''\
235231
Test function for rat module.

Demo/classes/bitvec.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,6 @@ def __invert__(self):
311311
return BitVec(~self._data & ((1 << self._len) - 1), \
312312
self._len)
313313

314-
def __coerce__(self, otherseq, *rest):
315-
#needed for *some* of the arithmetic operations
316-
#rprt('%r.__coerce__%r\n' % (self, (otherseq,) + rest))
317-
if type(otherseq) != type(self):
318-
otherseq = bitvec(otherseq, *rest)
319-
return self, otherseq
320-
321314
def __int__(self):
322315
return int(self._data)
323316

Doc/c-api/newtypes.rst

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ functionality. The fields of the type object are examined in detail in this
330330
section. The fields will be described in the order in which they occur in the
331331
structure.
332332

333-
Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc,
333+
Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, intargfunc,
334334
intintargfunc, intobjargproc, intintobjargproc, objobjargproc, destructor,
335335
freefunc, printfunc, getattrfunc, getattrofunc, setattrfunc, setattrofunc,
336336
cmpfunc, reprfunc, hashfunc
@@ -751,19 +751,6 @@ type objects) *must* have the :attr:`ob_size` field.
751751
:attr:`sq_inplace_repeat`.
752752

753753

754-
.. data:: Py_TPFLAGS_CHECKTYPES
755-
756-
If this bit is set, the binary and ternary operations in the
757-
:ctype:`PyNumberMethods` structure referenced by :attr:`tp_as_number` accept
758-
arguments of arbitrary object types, and do their own type conversions if
759-
needed. If this bit is clear, those operations require that all arguments have
760-
the current type as their type, and the caller is supposed to perform a coercion
761-
operation first. This applies to :attr:`nb_add`, :attr:`nb_subtract`,
762-
:attr:`nb_multiply`, :attr:`nb_divide`, :attr:`nb_remainder`, :attr:`nb_divmod`,
763-
:attr:`nb_power`, :attr:`nb_lshift`, :attr:`nb_rshift`, :attr:`nb_and`,
764-
:attr:`nb_xor`, and :attr:`nb_or`.
765-
766-
767754
.. data:: Py_TPFLAGS_HAVE_RICHCOMPARE
768755

769756
If this bit is set, the type object has the :attr:`tp_richcompare` field, as

Doc/glossary.rst

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,6 @@ Glossary
3232
One of the two flavors of classes in earlier Python versions. Since
3333
Python 3.0, there are no classic classes anymore.
3434

35-
coercion
36-
The implicit conversion of an instance of one type to another during an
37-
operation which involves two arguments of the same type. For example,
38-
``int(3.15)`` converts the floating point number to the integer ``3``, but
39-
in ``3+4.5``, each argument is of a different type (one int, one float),
40-
and both must be converted to the same type before they can be added or it
41-
will raise a ``TypeError``. Coercion between two operands can be
42-
performed with the ``coerce`` builtin function; thus, ``3+4.5`` is
43-
equivalent to calling ``operator.add(*coerce(3, 4.5))`` and results in
44-
``operator.add(3.0, 4.5)``. Without coercion, all arguments of even
45-
compatible types would have to be normalized to the same value by the
46-
programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``.
47-
4835
complex number
4936
An extension of the familiar real number system in which all numbers are
5037
expressed as a sum of a real part and an imaginary part. Imaginary
@@ -168,14 +155,14 @@ Glossary
168155
integer division
169156
Mathematical division discarding any remainder. For example, the
170157
expression ``11/4`` currently evaluates to ``2`` in contrast to the
171-
``2.75`` returned by float division. Also called *floor division*.
172-
When dividing two integers the outcome will always be another integer
173-
(having the floor function applied to it). However, if one of the operands
174-
is another numeric type (such as a :class:`float`), the result will be
175-
coerced (see :term:`coercion`) to a common type. For example, an integer
176-
divided by a float will result in a float value, possibly with a decimal
177-
fraction. Integer division can be forced by using the ``//`` operator
178-
instead of the ``/`` operator. See also :term:`__future__`.
158+
``2.75`` returned by float division. Also called *floor division*. When
159+
dividing two integers the outcome will always be another integer (having
160+
the floor function applied to it). However, if the operands types are
161+
different, one of them will be converted to the other's type. For
162+
example, an integer divided by a float will result in a float value,
163+
possibly with a decimal fraction. Integer division can be forced by using
164+
the ``//`` operator instead of the ``/`` operator. See also
165+
:term:`__future__`.
179166

180167
interactive
181168
Python has an interactive interpreter which means that you can try out

Doc/library/decimal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Decimal floating point objects share many properties with the other built-in
312312
numeric types such as :class:`float` and :class:`int`. All of the usual math
313313
operations and special methods apply. Likewise, decimal objects can be copied,
314314
pickled, printed, used as dictionary keys, used as set elements, compared,
315-
sorted, and coerced to another type (such as :class:`float` or :class:`long`).
315+
sorted, and converted to another type (such as :class:`float` or :class:`int`).
316316

317317
In addition to the standard numeric properties, decimal floating point objects
318318
also have a number of specialized methods:

Include/object.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
133133
typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
134134
typedef int (*inquiry)(PyObject *);
135135
typedef Py_ssize_t (*lenfunc)(PyObject *);
136-
typedef int (*coercion)(PyObject **, PyObject **);
137136
typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
138137
typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
139138
typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
@@ -222,7 +221,7 @@ typedef struct {
222221
binaryfunc nb_and;
223222
binaryfunc nb_xor;
224223
binaryfunc nb_or;
225-
coercion nb_coerce;
224+
int nb_reserved; /* unused, used to be nb_coerce */
226225
unaryfunc nb_int;
227226
unaryfunc nb_long;
228227
unaryfunc nb_float;

Modules/datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ static PyNumberMethods delta_as_number = {
20822082
0, /*nb_and*/
20832083
0, /*nb_xor*/
20842084
0, /*nb_or*/
2085-
0, /*nb_coerce*/
2085+
0, /*nb_reserved*/
20862086
0, /*nb_int*/
20872087
0, /*nb_long*/
20882088
0, /*nb_float*/

Objects/boolobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static PyNumberMethods bool_as_number = {
108108
bool_and, /* nb_and */
109109
bool_xor, /* nb_xor */
110110
bool_or, /* nb_or */
111-
0, /* nb_coerce */
111+
0, /* nb_reserved */
112112
0, /* nb_int */
113113
0, /* nb_long */
114114
0, /* nb_float */

Objects/complexobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ static PyNumberMethods complex_as_number = {
963963
0, /* nb_and */
964964
0, /* nb_xor */
965965
0, /* nb_or */
966-
(coercion)0, /* nb_coerce */
966+
0, /* nb_reserved */
967967
complex_int, /* nb_int */
968968
complex_long, /* nb_long */
969969
complex_float, /* nb_float */

Objects/floatobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ format_float(char *buf, size_t buflen, PyFloatObject *v, int precision)
235235
}
236236

237237
/* Macro and helper that convert PyObject obj to a C double and store
238-
the value in dbl; this replaces the functionality of the coercion
239-
slot function. If conversion to double raises an exception, obj is
238+
the value in dbl. If conversion to double raises an exception, obj is
240239
set to NULL, and the function invoking this macro returns NULL. If
241240
obj is not of float, int or long type, Py_NotImplemented is incref'ed,
242241
stored in obj, and returned from the function invoking this macro.
@@ -1069,7 +1068,7 @@ static PyNumberMethods float_as_number = {
10691068
0, /*nb_and*/
10701069
0, /*nb_xor*/
10711070
0, /*nb_or*/
1072-
(coercion)0, /*nb_coerce*/
1071+
0, /*nb_reserved*/
10731072
float_trunc, /*nb_int*/
10741073
float_trunc, /*nb_long*/
10751074
float_float, /*nb_float*/

0 commit comments

Comments
 (0)