[Python-Dev] Boolean type for Py3K?

Ka-Ping Yee ping@lfw.org
Fri, 17 Mar 2000 10:53:12 -0600 (CST)


On Fri, 17 Mar 2000, Barry A. Warsaw wrote:
> Almost a year ago, I mused about a boolean type in c.l.py, and came up
> with this prototype in Python.
> 
> -------------------- snip snip --------------------
> class Boolean:
[...]
> 
> I think it makes sense to augment Python's current truth rules with a
> built-in boolean type and True and False values.  But unless it's tied
> in more deeply (e.g. comparisons return one of these instead of
> integers -- and what are the implications of that?) then it's pretty
> much just syntactic sugar <0.75 lick>.

Yeah, and the whole point *is* the change in semantics, not the
syntactic sugar.  I'm hoping we can gain some safety from the
type checking... though i can't seem to think of a good example
off the top of my head.

It's easier to think of examples if things like 'if', 'and', 'or',
etc. only accept booleans as conditional arguments -- but i can't
imagine going that far, as that would just be really annoying.

Let's see.  Specifically, the following would probably return
booleans:

    magnitude comparisons:      <, >, <=, >=  (and __cmp__)
    value equality comparisons: ==, !=
    identity comparisons:       is, is not
    containment tests:          in, not in (and __contains__)

... and booleans would be different from integers in that
arithmetic would be illegal... but that's about it. (?)
Booleans are still storable immutable values; they could be
keys to dicts but not lists; i don't know what else.

Maybe this wouldn't actually buy us anything except for the
nicer spelling of "True" and "False", which might not be worth
it.  ... Hmm.  Can anyone think of common cases where this
could help?


-- n!?g