[Python-checkins] CVS: python/dist/src/Doc/lib libfuncs.tex,1.102,1.103 libstdtypes.tex,1.83,1.84

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 03 Apr 2002 14:41:52 -0800


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv31419/Doc/lib

Modified Files:
	libfuncs.tex libstdtypes.tex 
Log Message:
Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.



Index: libfuncs.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libfuncs.tex,v
retrieving revision 1.102
retrieving revision 1.103
diff -C2 -d -r1.102 -r1.103
*** libfuncs.tex	6 Mar 2002 02:29:30 -0000	1.102
--- libfuncs.tex	3 Apr 2002 22:41:50 -0000	1.103
***************
*** 78,81 ****
--- 78,91 ----
  \end{funcdesc}
  
+ \begin{funcdesc}{bool}{x}
+   Convert a value to a Boolean, using the standard truth testing
+   procedure.  If \code{x} is false, this returns \code{False};
+   otherwise it returns \code{True}.  \code{bool} is also a class,
+   which is a subclass of \code{int}.  Class \code{bool} cannot be
+   subclassed further.  Its only instances are \code{False} and
+   \code{True}.
+ \indexii{Boolean}{type}
+ \end{funcdesc}
+ 
  \begin{funcdesc}{buffer}{object\optional{, offset\optional{, size}}}
    The \var{object} argument must be an object that supports the buffer

Index: libstdtypes.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstdtypes.tex,v
retrieving revision 1.83
retrieving revision 1.84
diff -C2 -d -r1.83 -r1.84
*** libstdtypes.tex	12 Mar 2002 03:04:44 -0000	1.83
--- libstdtypes.tex	3 Apr 2002 22:41:50 -0000	1.84
***************
*** 3,10 ****
  The following sections describe the standard types that are built into
  the interpreter.  These are the numeric types, sequence types, and
! several others, including types themselves.  There is no explicit
! Boolean type; use integers instead.
  \indexii{built-in}{types}
- \indexii{Boolean}{type}
  
  Some operations are supported by several object types; in particular,
--- 3,8 ----
  The following sections describe the standard types that are built into
  the interpreter.  These are the numeric types, sequence types, and
! several others, including types themselves.
  \indexii{built-in}{types}
  
  Some operations are supported by several object types; in particular,
***************
*** 31,34 ****
--- 29,35 ----
  	\withsubitem{(Built-in object)}{\ttindex{None}}
  
+ \item	\code{False}
+ 	\withsubitem{(Built-in object)}{\ttindex{False}}
+ 
  \item	zero of any numeric type, for example, \code{0}, \code{0L},
          \code{0.0}, \code{0j}.
***************
*** 51,59 ****
  
  Operations and built-in functions that have a Boolean result always
! return \code{0} for false and \code{1} for true, unless otherwise
! stated.  (Important exception: the Boolean operations
! \samp{or}\opindex{or} and \samp{and}\opindex{and} always return one of
! their operands.)
! 
  
  \subsection{Boolean Operations \label{boolean}}
--- 52,61 ----
  
  Operations and built-in functions that have a Boolean result always
! return \code{0} or \code{False} for false and \code{1} or \code{True}
! for true, unless otherwise stated.  (Important exception: the Boolean
! operations \samp{or}\opindex{or} and \samp{and}\opindex{and} always
! return one of their operands.)
! \index{False}
! \index{True}
  
  \subsection{Boolean Operations \label{boolean}}
***************
*** 69,73 ****
    \hline
    \lineiii{not \var{x}}
!           {if \var{x} is false, then \code{1}, else \code{0}}{(2)}
  \end{tableiii}
  \opindex{and}
--- 71,75 ----
    \hline
    \lineiii{not \var{x}}
!           {if \var{x} is false, then \code{True}, else \code{False}}{(2)}
  \end{tableiii}
  \opindex{and}
***************
*** 162,167 ****
  \subsection{Numeric Types \label{typesnumeric}}
  
! There are four numeric types: \dfn{plain integers}, \dfn{long integers},
  \dfn{floating point numbers}, and \dfn{complex numbers}.
  Plain integers (also just called \dfn{integers})
  are implemented using \ctype{long} in C, which gives them at least 32
--- 164,171 ----
  \subsection{Numeric Types \label{typesnumeric}}
  
! There are four distinct numeric types: \dfn{plain integers},
! \dfn{long integers}, 
  \dfn{floating point numbers}, and \dfn{complex numbers}.
+ In addition, Booleans are a subtype of plain integers.
  Plain integers (also just called \dfn{integers})
  are implemented using \ctype{long} in C, which gives them at least 32
***************
*** 171,174 ****
--- 175,179 ----
  working with.
  \obindex{numeric}
+ \obindex{Boolean}
  \obindex{integer}
  \obindex{long integer}
***************
*** 1389,1392 ****
--- 1394,1413 ----
  
  It is written as \code{Ellipsis}.
+ 
+ \subsubsection{Boolean Values}
+ 
+ Boolean values are the two constant objects \code{False} and
+ \code{True}.  They are used to represent truth values (although other
+ values can also be considered false or true).  In numeric contexts
+ (for example when used as the argument to an arithmetic operator),
+ they behave like the integers 0 and 1, respectively.  The built-in
+ function \function{bool()} can be used to cast any value to a Boolean,
+ if the value can be interpreted as a truth value (see section Truth
+ Value Testing above).
+ 
+ They are written as \code{False} and \code{True}, respectively.
+ \index{False}
+ \index{True}
+ \indexii{Boolean}{values}