[Python-checkins] python/nondist/peps pep-0290.txt,1.5,1.6

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Sat, 25 Jan 2003 12:15:38 -0800


Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1:/tmp/cvs-serv8654

Modified Files:
	pep-0290.txt 
Log Message:
Added migration issue for booleans.


Index: pep-0290.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0290.txt,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** pep-0290.txt	15 Jan 2003 01:55:12 -0000	1.5
--- pep-0290.txt	25 Jan 2003 20:15:35 -0000	1.6
***************
*** 60,63 ****
--- 60,96 ----
  
  
+ Migration Issues
+ ================
+ 
+ Comparison Operators Not a Shortcut for Producing 0 or 1
+ --------------------------------------------------------
+ 
+ Prior to Python 2.3, comparison operations returned 0 or 1 rather
+ than True or False.  Some code may have used this as a shortcut for
+ producing zero or one in places where their boolean counterparts are
+ not appropriate.  For example::
+     
+     def identity(m=1):
+         """Create and m-by-m identity matrix"""
+         return [[i==j for i in range(m)] for j in range(m)]
+ 
+ In Python 2.2, a call to identity(2) would produce::
+ 
+     [[1, 0], [0, 1]]
+ 
+ In Python 2.3, the same call would produce::
+ 
+     [[True, False], [False, True]]
+ 
+ Since booleans are a subclass of integers, the matrix would continue
+ to calculate normally, but it will not print as expected.  The list
+ comprehension should be changed to read::
+ 
+     return [[i==j and 1 or 0 for i in range(m)] for j in range(m)]
+ 
+ There are similiar concerns when storing data to be used by other
+ applications which may expect a number instead of True or False.
+ 
+ 
  Modernization Procedures
  ========================