[Python-checkins] CVS: python/nondist/peps pep-0285.txt,1.2,1.3

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 08 Mar 2002 10:28:05 -0800


Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv24565

Modified Files:
	pep-0285.txt 
Log Message:
Some more clarifications.


Index: pep-0285.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0285.txt,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pep-0285.txt	8 Mar 2002 16:15:04 -0000	1.2
--- pep-0285.txt	8 Mar 2002 18:28:03 -0000	1.3
***************
*** 27,31 ****
      Most languages eventually grow a Boolean type; even C99 has one.
      It's useful to be able to tell from a function result that the
!     outcome has Boolean semantics.
  
  
--- 27,33 ----
      Most languages eventually grow a Boolean type; even C99 has one.
      It's useful to be able to tell from a function result that the
!     outcome has Boolean semantics, and it helps with things like RPC
!     protocols that may prefer to encode Booleans differently from
!     integers.
  
  
***************
*** 37,46 ****
          class bool(int):
  
!             def __new__(cls, val=0, _create=0):
!                 if _create:
!                     # This is nor part of the spec,
!                     # just a hack to bootstrap False and True
!                     return int.__new__(cls, not not val)
!                 elif val:
                      return True
                  else:
--- 39,46 ----
          class bool(int):
  
!             def __new__(cls, val=0):
!                 # This constructor doesn't return a new instance;
!                 # it returns an existing instance
!                 if val:
                      return True
                  else:
***************
*** 79,89 ****
              __rxor__ = __xor__
  
! 
!         False = bool(0, _create=1)
!         True = bool(1, _create=1)
  
      The values False and True will be singletons, like None; the C
      implementation will not allow other instances of bool to be
!     created.
  
      All built-in operations that are defined to return a Boolean
--- 79,91 ----
              __rxor__ = __xor__
  
!         # Bootstrap truth values through sheer willpower
!         False = int.__new__(bool, 0)
!         True = int.__new__(bool, 1)
  
      The values False and True will be singletons, like None; the C
      implementation will not allow other instances of bool to be
!     created.  At the C level, the existing globals Py_False and
!     Py_True will be identical to the built-in singletons False and
!     True.
  
      All built-in operations that are defined to return a Boolean
***************
*** 96,110 ****
      startswith(), and the closed attribute of file objects.
  
  
  Issues
  
      Because the repr() or str() of a bool value is different from an
!     int value, some code (e.g. doctest-based unit tests) may fail.
!     How much of a backwards compatibility problem this will be, I
!     don't know.  If we find this is a real problem, we could add a
!     command-line option to make False and True aliases for 0 and 1 and
!     bool an alias for int.
  
-                                    
  Copyright
  
--- 98,121 ----
      startswith(), and the closed attribute of file objects.
  
+     Note that subclassing from int means that True+1 is valid and
+     equals 2, and so on.  This is important for backwards
+     compatibility: because comparisons and so on currently return
+     integer values, there's no way of telling what uses existing
+     applications make of these values.
+ 
  
  Issues
  
      Because the repr() or str() of a bool value is different from an
!     int value, some code (e.g. doctest-based unit tests, and possibly
!     database code that relies on things like "%s" % truthvalue) may
!     fail.  How much of a backwards compatibility problem this will be,
!     I don't know.  If we find this is a real problem, we could add a
!     command-line option to change the repr() and str() of False and
!     True to be '0' and '1'; or we could make this the defined
!     behavior, but that would defeat some of the purpose (being able to
!     see that a printed result is intended to be a truth value).
! 
  
  Copyright