From 2baf604ac31e34e0a36eb6bd3b4ab3457eebee62 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Mon, 4 Feb 2013 10:07:08 +0800 Subject: [PATCH] Update HACKING.rst per recent changes Added "is not" usage with examples * https://review.openstack.org/#/c/20865/ Fixed "not in" usage description * https://review.openstack.org/#/c/20875/ Fixed some "not X in Y" corner cases. Change-Id: I7534ef73e6fd525fd8f4bee594a4b37524699c08 --- HACKING.rst | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 54e3b3275..213495832 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -28,16 +28,23 @@ General mylist = Foo().list() # OKAY, does not shadow built-in +- Use the "is not" operator when testing for unequal identities. Example:: -- Use the "not in" operator for collection membership evaluation. Example:: + if not X is Y: # BAD, intended behavior is ambiguous + pass - if not X in Y: # BAD, hard to understand + 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 is Z): # OKAY, still better than all those 'not's + if not (X in Y or X in Z): # OKAY, still better than all those 'not's pass