[openstack-dev] [nova] 'if foo' vs 'if foo is not None'

John Dennis jdennis at redhat.com
Mon Mar 3 16:06:16 UTC 2014

On 03/03/2014 10:00 AM, Matthew Booth wrote:
> PEP 8, under 'Programming Recommendations' recommends against implicit
> comparison to None. This isn't just stylistic, either: we were actually
> bitten by it in the VMware driver
> (https://bugs.launchpad.net/nova/+bug/1262288). The bug was hard to
> spot, and had consequences to resource usage.
> However, implicit comparison to None seems to be the default in Nova. Do
> I give up mentioning this in reviews, or is this something we care about?

IMHO testing for None is correct provided you've been disciplined in the
rest of your coding. None has a very specific meaning, it not just a
truth value [1]. My interpretation of None is None represents the
"Undefined Value" [2] which is semantically different than values which
evaluate to False (i.e. False, 0, empty sequence).

[1] http://docs.python.org/2/library/stdtypes.html#truth-value-testing

[2] Technically None is not an undefined value, however common
programming paradigms ascribe the undefined semantic to None.

More information about the OpenStack-dev mailing list