From 4cd7abaa350cc7b465b90a26e87f5c73e32a2d1f Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Thu, 31 Jan 2013 14:23:27 +0800 Subject: Fixes 'not in' operator usage Change-Id: I50a5bbe4800fc88b631701a6be0a0f9feec597d0 --- HACKING.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'HACKING.rst') diff --git a/HACKING.rst b/HACKING.rst index cf6abb39..bf0befca 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -18,6 +18,24 @@ General - Do not name anything the same name as a built-in or reserved word - When defining global constants, define them before functions and classes - Avoid using "double quotes" where you can reasonably use 'single quotes' +- Use the "is not" operator when testing for unequal identities. Example:: + + if not X is Y: # BAD, intended behavior is ambiguous + pass + + if X is not Y: # OKAY, intuitive + pass + +- Use the "not in" operator for evaluating membership in a collection. Example:: + + if not X in Y: # BAD, intended behavior is ambiguous + pass + + if X not in Y: # OKAY, intuitive + pass + + if not (X in Y or X in Z): # OKAY, still better than all those 'not's + pass TODO vs FIXME -- cgit