Make bin() implementation parallel oct() and hex() so that int/long subclasses can override or so that other classes can support.

This commit is contained in:
Raymond Hettinger 2008-06-20 04:18:15 +00:00
parent e0f124495b
commit e3ae655edf
7 changed files with 49 additions and 2 deletions

View file

@ -933,6 +933,12 @@ int_float(PyIntObject *v)
return PyFloat_FromDouble((double)(v -> ob_ival));
}
static PyObject *
int_bin(PyObject *v)
{
return PyNumber_ToBase(v, 2);
}
static PyObject *
int_oct(PyIntObject *v)
{
@ -1231,6 +1237,7 @@ static PyNumberMethods int_as_number = {
0, /* nb_inplace_floor_divide */
0, /* nb_inplace_true_divide */
(unaryfunc)int_int, /* nb_index */
(unaryfunc)int_bin, /* nb_bin */
};
PyTypeObject PyInt_Type = {