summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-07-28 16:55:13 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-07-28 16:55:13 (GMT)
commit66d2be898611f32e3840025055f2cd9b92b9f19c (patch)
treefdae9deaafd2bc799ba7092b92233e67bcef8b7c /Objects
parenta2250e61db26e6f03d035e8c16e5305e57714323 (diff)
downloadcpython-66d2be898611f32e3840025055f2cd9b92b9f19c.zip
cpython-66d2be898611f32e3840025055f2cd9b92b9f19c.tar.gz
cpython-66d2be898611f32e3840025055f2cd9b92b9f19c.tar.bz2
Issue 12647: Add __bool__() method to the None object.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 05c52f1..27d7089 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1255,7 +1255,7 @@ PyObject_Dir(PyObject *obj)
}
/*
-None is as a non-NULL undefined value.
+None is a non-NULL undefined value.
There is (and should be!) no way to create other objects of this type,
so there is exactly one (which is indestructible, by the way).
*/
@@ -1277,6 +1277,48 @@ none_dealloc(PyObject* ignore)
Py_FatalError("deallocating None");
}
+static int
+none_bool(PyObject *v)
+{
+ return 0;
+}
+
+static PyNumberMethods none_as_number = {
+ 0, /* nb_add */
+ 0, /* nb_subtract */
+ 0, /* nb_multiply */
+ 0, /* nb_remainder */
+ 0, /* nb_divmod */
+ 0, /* nb_power */
+ 0, /* nb_negative */
+ 0, /* nb_positive */
+ 0, /* nb_absolute */
+ (inquiry)none_bool, /* nb_bool */
+ 0, /* nb_invert */
+ 0, /* nb_lshift */
+ 0, /* nb_rshift */
+ 0, /* nb_and */
+ 0, /* nb_xor */
+ 0, /* nb_or */
+ 0, /* nb_int */
+ 0, /* nb_reserved */
+ 0, /* nb_float */
+ 0, /* nb_inplace_add */
+ 0, /* nb_inplace_subtract */
+ 0, /* nb_inplace_multiply */
+ 0, /* nb_inplace_remainder */
+ 0, /* nb_inplace_power */
+ 0, /* nb_inplace_lshift */
+ 0, /* nb_inplace_rshift */
+ 0, /* nb_inplace_and */
+ 0, /* nb_inplace_xor */
+ 0, /* nb_inplace_or */
+ 0, /* nb_floor_divide */
+ 0, /* nb_true_divide */
+ 0, /* nb_inplace_floor_divide */
+ 0, /* nb_inplace_true_divide */
+ 0, /* nb_index */
+};
static PyTypeObject PyNone_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
@@ -1289,7 +1331,7 @@ static PyTypeObject PyNone_Type = {
0, /*tp_setattr*/
0, /*tp_reserved*/
none_repr, /*tp_repr*/
- 0, /*tp_as_number*/
+ &none_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */