[Python-Dev] For review: PEP 285: Adding a bool type

Samuele Pedroni pedroni@inf.ethz.ch
Sat, 9 Mar 2002 22:01:36 +0100


From: M.-A. Lemburg <mal@lemburg.com>
> 
> +1 on making bool an abstract subtype of integers
>    and having Py_True and Py_False as only instances
> 
> -1 on overriding interfaces other than informational
>    ones such as __repr__
> 

So you mean just:

class truth(int): # other names?, should not be subclassable
  def __new__(cls,val): # ??
    if val:
      return true
    else:
      return false
  def __repr__(self):
    if  self:
      return 'true'
   else:
     return 'false'

true = int.__new__(truth,1) # also Py_True
false = int.__new__(truth,0) # also Py_False