mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
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:
parent
e0f124495b
commit
e3ae655edf
7 changed files with 49 additions and 2 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue