mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
e9c0358bf4
commit
77f6a65eb0
29 changed files with 489 additions and 378 deletions
|
@ -162,7 +162,7 @@ complex numbers:
|
|||
These represent elements from the mathematical set of whole numbers.
|
||||
\obindex{integer}
|
||||
|
||||
There are two types of integers:
|
||||
There are three types of integers:
|
||||
|
||||
\begin{description}
|
||||
|
||||
|
@ -187,6 +187,17 @@ represented in a variant of 2's complement which gives the illusion of
|
|||
an infinite string of sign bits extending to the left.
|
||||
\obindex{long integer}
|
||||
|
||||
\item[Booleans]
|
||||
These represent the truth values False and True. The two objects
|
||||
representing the values False and True are the only Boolean objects.
|
||||
The Boolean type is a subtype of plain integers, and Boolean values
|
||||
behave like the values 0 and 1, respectively, in almost all contexts,
|
||||
the exception being that when converted to a string, the strings
|
||||
\code{"False"} or \code{"True"} are returned, respectively.
|
||||
\obindex{Boolean}
|
||||
\ttindex{False}
|
||||
\ttindex{True}
|
||||
|
||||
\end{description} % Integers
|
||||
|
||||
The rules for integer representation are intended to give the most
|
||||
|
@ -222,6 +233,7 @@ and \code{z.imag}.
|
|||
|
||||
\end{description} % Numbers
|
||||
|
||||
|
||||
\item[Sequences]
|
||||
These represent finite ordered sets indexed by non-negative numbers.
|
||||
The built-in function \function{len()}\bifuncindex{len} returns the
|
||||
|
@ -1074,8 +1086,10 @@ wrong hash bucket).
|
|||
\end{methoddesc}
|
||||
|
||||
\begin{methoddesc}[object]{__nonzero__}{self}
|
||||
Called to implement truth value testing; should return \code{0} or
|
||||
\code{1}. When this method is not defined, \method{__len__()} is
|
||||
Called to implement truth value testing, and the built-in operation
|
||||
\code{bool()}; should return \code{False} or \code{True}, or their
|
||||
integer equivalents \code{0} or \code{1}.
|
||||
When this method is not defined, \method{__len__()} is
|
||||
called, if it is defined (see below). If a class defines neither
|
||||
\method{__len__()} nor \method{__nonzero__()}, all its instances are
|
||||
considered true.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue