PEP 285: Adding a bool type

John Roth johnroth at ameritech.net
Sat Mar 30 07:46:29 EST 2002


"Guido van Rossum" <guido at python.org> wrote in message
news:mailman.1017466974.6751.python-list at python.org...
> I offer the following PEP for review by the community.  If it receives
> a favorable response, it will be implemented in Python 2.3.
>
>     I'm particularly interested in hearing your opinion about the
>     following three issues:
>
>     1) Should this PEP be accepted at all.

Yes. I think it will improve the readability of code.

>     2) Should str(True) return "True" or "1": "1" might reduce
>        backwards compatibility problems, but looks strange to me.
>        (repr(True) would always return "True".)

That's a hard one. In general, I'd have to go with str(True)
returning 1 for compatability reasons. If you don't, I would
expect unit test suites to break, as well as anything that
externalizes values as strings and then loads them again.

Also, repr() should be documented as being changable
from release to release - that is, the result of repr() is intended
to be fed back into eval() in that release.

>     3) Should the constants be called 'True' and 'False'
>        (corresponding to None) or 'true' and 'false' (as in C++, Java
>        and C99).

Keep it consistent with None. True and False.

>     4) Should we strive to eliminate non-Boolean operations on bools
>        in the future, through suitable warnings, so that e.g. True+1
>        would eventually (e.g. in Python 3000 be illegal).  Personally,
>        I think we shouldn't; 28+isleap(y) seems totally reasonable to
>        me.

Actually, the example seems totally unreasonable to me. It's
treating the fact that February in a leap year has one more day
than February in a non leap year as a magic number. Bad! Bad!

More to the point, if bool is a subtype of integer, I don't see
anything wrong with the type coercion, and I don't see very
much value with the purist viewpoint. This could be looked at
again if there is ever a version of Python with strong typing.

>     5) Should operator.truth(x) return an int or a bool.  Tim Peters
>        believes it should return an int because it's been documented
>        as such.  I think it should return a bool; most other standard
>        predicates (e.g. issubtype()) have also been documented as
>        returning 0 or 1, and it's obvious that we want to change those
>        to return a bool.

Logically, it should return a bool. However, I'm quite willing
to settle for whatever is needed for compatability (breaking the
least amount of code.)

John Roth





More information about the Python-list mailing list