verify(eval("x %s c[y]" % op) == eval("x %s y" % op),
"x=%d, y=%d" % (x, y))
+def coercions():
+ if verbose: print "Testing coercions..."
+ class I(int): pass
+ coerce(I(0), 0)
+ coerce(0, I(0))
+ class L(long): pass
+ coerce(L(0), 0)
+ coerce(L(0), 0L)
+ coerce(0, L(0))
+ coerce(0L, L(0))
+ class F(float): pass
+ coerce(F(0), 0)
+ coerce(F(0), 0L)
+ coerce(F(0), 0.)
+ coerce(0, F(0))
+ coerce(0L, F(0))
+ coerce(0., F(0))
+ class C(complex): pass
+ coerce(C(0), 0)
+ coerce(C(0), 0L)
+ coerce(C(0), 0.)
+ coerce(C(0), 0j)
+ coerce(0, C(0))
+ coerce(0L, C(0))
+ coerce(0., C(0))
+ coerce(0j, C(0))
+
def all():
lists()
str_subclass_as_dict_key()
classic_comparisons()
rich_comparisons()
+ coercions()
all()
return PyInt_FromLong(a | b);
}
+static int
+int_coerce(PyObject **pv, PyObject **pw)
+{
+ if (PyInt_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
+ return 1; /* Can't do it */
+}
+
static PyObject *
int_int(PyIntObject *v)
{
(binaryfunc)int_and, /*nb_and*/
(binaryfunc)int_xor, /*nb_xor*/
(binaryfunc)int_or, /*nb_or*/
- 0, /*nb_coerce*/
+ int_coerce, /*nb_coerce*/
(unaryfunc)int_int, /*nb_int*/
(unaryfunc)int_long, /*nb_long*/
(unaryfunc)int_float, /*nb_float*/