[openstack-dev] "if X not in Y" vs. "if not X in Y" consensus?

Vishvananda Ishaya vishvananda at gmail.com
Thu Jan 31 15:57:49 UTC 2013


On Jan 31, 2013, at 7:35 AM, Dean Troyer <dtroyer at gmail.com> wrote:

> On Thu, Jan 31, 2013 at 8:52 AM, Dolph Mathews <dolph.mathews at gmail.com> wrote:
>> +1 for "X not in Y"
>> 
>> "not X in Y" reads ambiguously to me.
> 
> And there's the reason it matters...it actually is not ambiguous
> according to operator precedence rules
> (http://docs.python.org/2/reference/expressions.html#not-in):
> 
> in "X not in Y" 'not' is part of the membership operator
> 
> in "not X in Y" 'not' is a boolean operator on X, returning True or False

The in operator has precedence over not so to have not be an operator on X
you would need:

(not X) in Y

IMO, it seems a little excessive to require one form over the other, but I
slightly prefer X not in Y as well.

Vish

> 
> These really are different operations that may have the same result
> for some data types and values.  Phew!  There is still only one way to
> do it right...
> 
> dt
> 
> -- 
> 
> Dean Troyer
> dtroyer at gmail.com
> 
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev




More information about the OpenStack-dev mailing list