<br><br><div class="gmail_quote">On Thu, Jul 28, 2011 at 09:55, raymond.hettinger <span dir="ltr">&lt;<a href="mailto:python-checkins@python.org">python-checkins@python.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<a href="http://hg.python.org/cpython/rev/ccce01988603" target="_blank">http://hg.python.org/cpython/rev/ccce01988603</a><br>
changeset:   71542:ccce01988603<br>
user:        Raymond Hettinger &lt;<a href="mailto:python@rcn.com">python@rcn.com</a>&gt;<br>
date:        Thu Jul 28 09:55:13 2011 -0700<br>
summary:<br>
  Issue 12647: Add __bool__() method to the None object.<br>
<br>
files:<br>
  Lib/test/test_descr.py |   3 -<br>
  Misc/NEWS              |   4 ++<br>
  Objects/object.c       |  46 ++++++++++++++++++++++++++++-<br>
  3 files changed, 48 insertions(+), 5 deletions(-)<br>
<br>
<br>
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py<br>
--- a/Lib/test/test_descr.py<br>
+++ b/Lib/test/test_descr.py<br>
@@ -2068,9 +2068,6 @@<br>
         # Two essentially featureless objects, just inheriting stuff from<br>
         # object.<br>
         self.assertEqual(dir(NotImplemented), dir(Ellipsis))<br>
-        if support.check_impl_detail():<br>
-            # None differs in PyPy: it has a __nonzero__<br>
-            self.assertEqual(dir(None), dir(Ellipsis))<br>
<br></blockquote><div><br>Wasn&#39;t this change only in 3.3 where __nonzero__ doesn&#39;t exist? So when PyPy eventually supports Python 3 they will have to update to support __bool__ on None but this test won&#39;t exercise that for them. IOW I think the guard is wrong and should go.<br>

<br>-Brett<br><br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
         # Nasty test case for proxied objects<br>
         class Wrapper(object):<br>
diff --git a/Misc/NEWS b/Misc/NEWS<br>
--- a/Misc/NEWS<br>
+++ b/Misc/NEWS<br>
@@ -13,6 +13,10 @@<br>
 - Verify the types of AST strings and identifiers provided by the user before<br>
   compiling them.<br>
<br>
+- Issue #12647: The None object now has a __bool__() method that returns False.<br>
+  Formerly, bool(None) returned False only because of special case logic<br>
+  in PyObject_IsTrue().<br>
+<br>
 - Issue #12579: str.format_map() now raises a ValueError if used on a<br>
   format string that contains positional fields. Initial patch by<br>
   Julian Berman.<br>
diff --git a/Objects/object.c b/Objects/object.c<br>
--- a/Objects/object.c<br>
+++ b/Objects/object.c<br>
@@ -1255,7 +1255,7 @@<br>
 }<br>
<br>
 /*<br>
-None is as a non-NULL undefined value.<br>
+None is a non-NULL undefined value.<br>
 There is (and should be!) no way to create other objects of this type,<br>
 so there is exactly one (which is indestructible, by the way).<br>
 */<br>
@@ -1277,6 +1277,48 @@<br>
     Py_FatalError(&quot;deallocating None&quot;);<br>
 }<br>
<br>
+static int<br>
+none_bool(PyObject *v)<br>
+{<br>
+    return 0;<br>
+}<br>
+<br>
+static PyNumberMethods none_as_number = {<br>
+    0,                          /* nb_add */<br>
+    0,                          /* nb_subtract */<br>
+    0,                          /* nb_multiply */<br>
+    0,                          /* nb_remainder */<br>
+    0,                          /* nb_divmod */<br>
+    0,                          /* nb_power */<br>
+    0,                          /* nb_negative */<br>
+    0,                          /* nb_positive */<br>
+    0,                          /* nb_absolute */<br>
+    (inquiry)none_bool,         /* nb_bool */<br>
+    0,                          /* nb_invert */<br>
+    0,                          /* nb_lshift */<br>
+    0,                          /* nb_rshift */<br>
+    0,                          /* nb_and */<br>
+    0,                          /* nb_xor */<br>
+    0,                          /* nb_or */<br>
+    0,                          /* nb_int */<br>
+    0,                          /* nb_reserved */<br>
+    0,                          /* nb_float */<br>
+    0,                          /* nb_inplace_add */<br>
+    0,                          /* nb_inplace_subtract */<br>
+    0,                          /* nb_inplace_multiply */<br>
+    0,                          /* nb_inplace_remainder */<br>
+    0,                          /* nb_inplace_power */<br>
+    0,                          /* nb_inplace_lshift */<br>
+    0,                          /* nb_inplace_rshift */<br>
+    0,                          /* nb_inplace_and */<br>
+    0,                          /* nb_inplace_xor */<br>
+    0,                          /* nb_inplace_or */<br>
+    0,                          /* nb_floor_divide */<br>
+    0,                          /* nb_true_divide */<br>
+    0,                          /* nb_inplace_floor_divide */<br>
+    0,                          /* nb_inplace_true_divide */<br>
+    0,                          /* nb_index */<br>
+};<br>
<br>
 static PyTypeObject PyNone_Type = {<br>
     PyVarObject_HEAD_INIT(&amp;PyType_Type, 0)<br>
@@ -1289,7 +1331,7 @@<br>
     0,                  /*tp_setattr*/<br>
     0,                  /*tp_reserved*/<br>
     none_repr,          /*tp_repr*/<br>
-    0,                  /*tp_as_number*/<br>
+    &amp;none_as_number,    /*tp_as_number*/<br>
     0,                  /*tp_as_sequence*/<br>
     0,                  /*tp_as_mapping*/<br>
     0,                  /*tp_hash */<br>
<font color="#888888"><br>
--<br>
Repository URL: <a href="http://hg.python.org/cpython" target="_blank">http://hg.python.org/cpython</a><br>
</font><br>_______________________________________________<br>
Python-checkins mailing list<br>
<a href="mailto:Python-checkins@python.org">Python-checkins@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-checkins" target="_blank">http://mail.python.org/mailman/listinfo/python-checkins</a><br>
<br></blockquote></div><br>