diff options
author | Guido van Rossum <guido@python.org> | 2001-09-19 01:25:16 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-09-19 01:25:16 (GMT) |
commit | 1952e388ca63b8eaa090bef966dd538f78ece208 (patch) | |
tree | 31afd318ac859dfbe337d2cf6e11fc6c10bcb45f /Objects/intobject.c | |
parent | d5d8e4a43632d9d4ec9f6fb23f7405c4f0678617 (diff) | |
download | cpython-1952e388ca63b8eaa090bef966dd538f78ece208.zip cpython-1952e388ca63b8eaa090bef966dd538f78ece208.tar.gz cpython-1952e388ca63b8eaa090bef966dd538f78ece208.tar.bz2 |
Add additional coercion support for "self subtypes" to int, long,
float (compare the recent checkin to complex). Added tests for these.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 16e4336..bb5ad16 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -782,6 +782,17 @@ int_or(PyIntObject *v, PyIntObject *w) 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) { @@ -904,7 +915,7 @@ static PyNumberMethods int_as_number = { (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*/ |