[Python-checkins] peps: Prefer "is not" over "not ... is". Closes 21540.

barry.warsaw python-checkins at python.org
Wed May 21 00:14:24 CEST 2014


http://hg.python.org/peps/rev/4aec4d180429
changeset:   5482:4aec4d180429
user:        Barry Warsaw <barry at python.org>
date:        Tue May 20 18:14:17 2014 -0400
summary:
  Prefer "is not" over "not ... is".  Closes 21540.

files:
  pep-0008.txt |  12 ++++++++++++
  1 files changed, 12 insertions(+), 0 deletions(-)


diff --git a/pep-0008.txt b/pep-0008.txt
--- a/pep-0008.txt
+++ b/pep-0008.txt
@@ -919,6 +919,18 @@
   have a type (such as a container) that could be false in a boolean
   context!
 
+- Use ``is not`` operator rather than ``not ... is``.  While both
+  expressions are functionally identical, the former is more readable
+  and preferred.
+  
+  Yes::
+  
+      if foo is not None:
+      
+  No::
+  
+      if not foo is None:
+
 - When implementing ordering operations with rich comparisons, it is
   best to implement all six operations (``__eq__``, ``__ne__``,
   ``__lt__``, ``__le__``, ``__gt__``, ``__ge__``) rather than relying

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list