Vedran Čačić added the comment:

Ok, so let me try to summarize.

Some people realized that & and | on bools are overridden to return bools 
instead of ints, and thought it would be nice if ~ acted as negation on bools 
(~False being True and ~True being false) instead of mapping them to -1 and -2 
as it currently does.

A (weak, IMO) counterargument is that currently int(a op b) == int(a) op int(b) 
for all ints a and b, even those ints that are also bools. But of course 
str(True) != str(1), so of course _some_ special methods can be overridden with 
a different behavior (returning non-equal things).

A better (again IMO) counterargument is that those (&, |, ~) operators are 
meant to be bitwise, that is, threaded over all the bits in the operands. In 
that case, bool with that ~ implementation should not be looked at as a 
subclass of int* qua long in Py2 (infinite number of bits to the left), but as 
a subclass of "int1" in the sense of Py2 int being int32 (fixed number of 
bits). But if we are to drive this to the natural conclusion, then True == -1 
when upcasted to int, not 1, and that would probably break too much code. Also, 
there are bitwise operators (<<, >>) which don't have a nice analogue on int1 
(except always returning 0, which is not interesting).

Also (wasn't mentioned in the thread, but probably worth mentioning), Python 3 
really tries to not have fixed-length ints anywhere. For example, indexing 
bytes gives ints, and they are not int8, but ordinary int*: ~b'a'[0] is -98, 
not 158. Bools might be special, but they are probably not _that_ special. We 
have worked long and hard to remove fixed-length ints from Python, it would be 
very counterproductive to add them back again.

The only reason I'm bringing this here, is that Guido said at some moment

> So we're either going to introduce it in 3.6 and tell people
about it in case their code might break, or we're never going to do
it.

and I would feel bad to tell future learners of Python "that feature was 
considered, but we simply forgot about it and the opportunity closed". :-O

If the sentiment has really crystallized to "we shouldn't do this" in the 
meantime, no problem. But it seems no pronouncement was made.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27754>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to