[Python-Dev] Boolean transition

Paul Prescod paul@prescod.net
Sun, 10 Mar 2002 17:51:44 -0800


Guido van Rossum wrote:
> 
>...
> 
> I don't know about others, but *my* arguments for making bool a
> subtype of int has *nothing* to do with the fact that ints can be used
> in a bool context.  (That would be reversing the inheritance, as you
> point out.)  It is rather the opposite: bool values gotten from
> certain operations (e.g. comparisons, and most built-in predicate
> functions) are commonly used in int contexts, because they are
> currently represented by 0 and 1.  So the constraint under which we're
> operating is that bool values must be ints.  This constraint has only
> two possible solutions: (a) continue to use int as the type of choice
> for bool results, and define builtins False = 0 and True = 1; or (b)
> make bool a subtype of int.

Agree 100%. The question is whether five years or ten years or twenty
years from now booleans will still be a subtype of integers. We have
deprecation techniques that allow us to start a transition to a world
where logic and integer arithmetic are completely separate.

> I do not want to say that in the future only bool is acceptable in a
> Boolean context; it would remove too many of my favorite ways of
> expression things clearly with few words. 

I agree with this too. The question is whether Python 3000 will still
allow this without error:

def foo(int_size, b_metric_unit):
  if b_metric_unit:
	return int_size * 10

foo(false, 10)

I would say that one day (not tomorrow!) the multiplication of a boolean
should raise an assertion as nonsensical.

 Paul Prescod