<div dir="auto"><div>There are few cases where I would approve of 'if x is True'. However, the names used in the example suggest it could be one of those rare cases. Settings of True/False/None (i.e. not set) seem like a reasonable pattern. In fact, in code like that, merely "truthy" values are probably a bug that should not pass silently. Obviously this depends on the surrounding code to decide.<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 18, 2019, 5:44 PM Greg Ewing <<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Richard Damon wrote:<br>
> On 3/18/19 7:27 AM, Greg Ewing wrote:<br>
> <br>
>>    if settings[MY_KEY]:<br>
>>        ...<br>
 ><br>
> That means something VERY different.<br>
<br>
Yes, but there needs to be justification for why the difference<br>
matters and why this particular way is the best way to deal<br>
with it.<br>
<br>
Whenever you write 'x is True' or 'x == True', you are putting<br>
a burden on all code that assigns to x to ensure that the<br>
value is actually an instance of bool rather than just a<br>
truthy or falsy value. That's an unusual requiremebt that<br>
can lead to obscure bugs.<br>
<br>
In the tri-state example, the way I would do it is to guard<br>
uses of it with 'if x is not None' and then treat the other<br>
values as truthy or falsy.<br>
<br>
-- <br>
Greg<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div></div>