NoneType and new instances

Terry Reedy tjreedy at udel.edu
Sat Jul 30 23:34:11 EDT 2011


On 7/30/2011 12:39 PM, bruno.desthuilliers at gmail.com wrote:
> On 28 juil, 17:39, Ethan Furman<et... at stoneleaf.us>  wrote:
>>
>> -->  bool(0) is bool(0)
>> True

> This test is not reliable

It is in the sense that it will always work -- because False/True are 
doubletone constants and so documented.

But expr is expr == True does not reliably say it will always be true, 
because

 > - a same id can be reused for terms (I have
> already seen such things happening). If you want a reliable test, use:
>
> #>  a = bool(0)
> #>  b = bool(0)
> #>  a is b
> True
>
> Note that this still fails to prove anything since bool is a subclass
> of int and CPython caches "small" integers:
>
> #>  a = 42
> #>  b = 42
> #>  a is b
> True




More information about the Python-list mailing list