Page MenuHomePhabricator

debugcommands: prevent using `is False`
Needs ReviewPublic

Authored by pulkit on Wed, Feb 17, 2:43 PM.

Details

Reviewers
Alphare
marmoute
Group Reviewers
hg-reviewers
Summary

I was touching this code in a future patch and marmoute warned about usage of
is False here.

Quoting marmoute:

"is False" is going to check if the object you have the very same object in
memory than the one Python allocated for False (in practice 0)
This will "mostly work" on cpython because of implementation details, but
is semantically wrong and can start breaking unexpectedly

Diff Detail

Repository
rHG Mercurial
Branch
default
Lint
No Linters Available
Unit
No Unit Test Coverage

Event Timeline

pulkit created this revision.Wed, Feb 17, 2:43 PM

I was touching this code in a future patch and marmoute warned about usage of is False here.
Quoting marmoute:

"is False" is going to check if the object you have the very same object in
memory than the one Python allocated for False (in practice 0)
This will "mostly work" on cpython because of implementation details, but
is semantically wrong and can start breaking unexpectedly

Is if foo == False valid in this case? I probably got my wires crossed with is None. (I'm fine with the code change here, just wondering for future reference.)

Alphare accepted this revision.Tue, Feb 23, 4:20 AM
Alphare added a subscriber: Alphare.

Is if foo == False valid in this case? I probably got my wires crossed with is None. (I'm fine with the code change here, just wondering for future reference.)

You will probably always want to use if not foo instead. if is None checks against the None singleton, so it's fine, but there is no singleton (aside from implementation details as marmoute said) for booleans in Python.

marmoute accepted this revision.Mon, Mar 1, 3:51 AM
marmoute added a subscriber: marmoute.