True inconsistency in Python
Erik Max Francis
max at alcyone.com
Tue Nov 18 04:30:55 EST 2003
Ron Adam wrote:
> The main inconsistencies of 'True' and 'False' are due to the
> possibility of the names 'True' and 'False' being reassigned.
>
> And the best way to fix this is by making 'True' and 'False' literals
> or constants.
But True and False are no different from None, int, str, or any of the
other builtins.
> It looks to me the benefits of changing this one item are worthwhile,
> and the drawbacks if it very low. It is also consistent to have them
> as basic constants and/or literals in the same way digits and the
> alphabet are. The values True and False are to Type boo() as digits
> are to int() or floats(), and as the alphabet is to string().
But, as I said, you're not going to run into this problem unless you're
doing unsafe things already (like `from module import *'), or letting
people you don't trust edit your source. I don't see this as a big
problem.
Accidental rebindings of things like int, str, and other builtin
types/functions with common names seem _far_ more common than
"accidentally" rebinding True or False.
> So they have not special property of there own. From what I
> understand, being a built in is a matter of where the code is, and
> doesn't have anything to do with what it does. It's a practical
> matter that the most frequently used items are built ins.
Yes. And builtins other than True and False are far more frequently
accidentally rebound.
> So the inconsistency I saw was in that True and False are not treated
> the same as other types made up from literals. 1 is always equal to
> 1, and it's never equal to 2. The same can't be said for True and
> False and bool(),
It's not true for int, either.
> Terry Reedy has pointed out to me that this will likely be changed in
> the future. I think it will make Python more consistent by preventing
> the possible reassignments of True, False, and None.
It will change in the sense that rebinding these names may result in
warnings or errors (already there's a warning for rebinding None in the
usual way), not that they'll become literals.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ God will forgive me; that's his business.
-- Heinrich Heine
More information about the Python-list
mailing list