This is an archive of the discontinued LLVM Phabricator instance.

[lit] Compare to None using identity, not equality
ClosedPublic

Authored by modocache on Oct 2 2016, 6:22 PM.

Details

Summary

In Python, None is a singleton, so checking whether a variable is
None may be done with is or is not. This has a slight advantage
over equiality comparisons == None and != None, since __eq__ may
be overridden in Python to produce sometimes unexpected results.

Using is None and is not None is also recommended practice in
https://www.python.org/dev/peps/pep-0008:

Comparisons to singletons like None should always be done with is or
is not, never the equality operators.

Event Timeline

modocache updated this revision to Diff 73227.Oct 2 2016, 6:22 PM
modocache retitled this revision from to [lit] Compare to None using identity, not equality.
modocache updated this object.
modocache added reviewers: ddunbar, echristo, beanz.
modocache added a subscriber: llvm-commits.
beanz accepted this revision.Oct 2 2016, 6:24 PM
beanz edited edge metadata.

LGTM!

This revision is now accepted and ready to land.Oct 2 2016, 6:24 PM
modocache updated this object.Oct 2 2016, 6:24 PM
modocache edited edge metadata.

Thanks! I'll need you or someone else to commit for me. :)

beanz added a comment.Oct 2 2016, 9:57 PM

Committed in rL283088. Thanks for the patch!

modocache closed this revision.Oct 3 2016, 4:51 PM

Thanks!