<var> is None vs. <var> == None

Steve Holden steve at holdenweb.com
Mon Jan 26 22:10:02 CET 2009

Terry Reedy wrote:
> Steve Holden wrote:
>> Terry Reedy wrote:
>>> In 2.x, the *names* 'True' and 'False' can be rebound because bool is
>>> new and people write
>>> try:
>>>   False,True
>>> except NameError:
>>>   False,True = 0,1
>>> to make code back compatible.
>> I would claim that the ability to rebind True and False is a simple bug,
>> though one not likely to be fixed in an 2.x release. The code above
>> doesn't rebind True and False in interpreters that have them ...
> In pre-bool 2.x, people never wrote the above but sometime wrote
>   False,True = 0,1
Right. This is the use case I overlooked.

> To me it is hardly a bug to not gratuitously break substantial amounts
> of proper code.
I quite agree. I take it all back!

>>> Back before rebinding 'None' was prohibited, 'is None' was not
>>> completely guaranteed either (absent reading the rest of a file to be
>>> sure no rebinding would be done).
>> And that was a bug too, in this case one that *was* removed in 2.4, I
>> believe. Don't have 2.3 lying around just now.
> Unlike with True and False, the devs could not think of or find any
> proper use case for rebinding None and judged that the new prohibition
> would break very little if any code.  As far as I know, they were correct.
Indeed they were.

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/

More information about the Python-list mailing list