summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-06-20 04:18:15 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-06-20 04:18:15 (GMT)
commite3ae655edfea3dd8ed32fcca63cb3eae861a58b7 (patch)
treeb1624452b23a4e614e103735dbe7e2a581b159bc /Objects/intobject.c
parente0f124495b0c0d7826ef1e64a8db27ebe28ed085 (diff)
downloadcpython-e3ae655edfea3dd8ed32fcca63cb3eae861a58b7.zip
cpython-e3ae655edfea3dd8ed32fcca63cb3eae861a58b7.tar.gz
cpython-e3ae655edfea3dd8ed32fcca63cb3eae861a58b7.tar.bz2
Make bin() implementation parallel oct() and hex() so that int/long subclasses can override or so that other classes can support.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index f98aee0..5210ee8 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -934,6 +934,12 @@ int_float(PyIntObject *v)
}
static PyObject *
+int_bin(PyObject *v)
+{
+ return PyNumber_ToBase(v, 2);
+}
+
+static PyObject *
int_oct(PyIntObject *v)
{
return _PyInt_Format(v, 8, 0);
@@ -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 = {