[Python-Dev] PEP 326 (quick location possibility)

Tim Peters tim.one at comcast.net
Thu Jan 29 21:46:29 EST 2004


[Andrew P. Lentvorski, Jr.]
> The code is still brittle.  If score(candidate) returns None, hilarity
> ensues.
>
> ...
> If magnitude comparisons involving None raised some kind of Exception,
> this would not be an issue.

I agree, but that's also a different issue.  I think people get tripped up
more often by that int < string is always true, and they'd get more relief
from that class of bug if mixing ints with strings in (at least < <= > and
>=) comparisons raised TypeError.

That plain None evaluates as false in a Boolean context is also a source of
nasty bugs.  Even Guido <wink> has been bitten by that.  Code like

    if not thing:
        ...

when thing is initialized to None is common in some codebases, and can
easily do a wrong thing when the *intent* was to say "if thing has been
bound to a value other than None", i.e. if the actual intent was

    if thing is not None:
        ...

Viewing None as "something that's not really there", it's neither true nor
false, so an exception would make sense to me here too.

But those are all incompatible changes.  Adding some new singleton objects
would not have been.




More information about the Python-Dev mailing list