[Python-checkins] CVS: python/nondist/peps pep-0237.txt,1.8,1.9

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 14 Aug 2001 11:37:47 -0700


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

Modified Files:
	pep-0237.txt 
Log Message:
Add an example.


Index: pep-0237.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0237.txt,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** pep-0237.txt	2001/08/14 18:13:50	1.8
--- pep-0237.txt	2001/08/14 18:37:44	1.9
***************
*** 206,209 ****
--- 206,233 ----
  
  
+ Example
+ 
+     If you pass a long int to a C function or built-in operation that
+     takes an integer, it will be treated the same as as a short int as
+     long as the value fits (by virtue of how PyArg_ParseTuple() is
+     implemented).  If the long value doesn't fit, it will still raise
+     an OverflowError.  For example:
+ 
+       def fact(n):
+           if n <= 1:
+               return 1
+           return n*fact(n-1)
+ 
+       A = "ABCDEFGHIJKLMNOPQ"
+       n = input("Gimme an int: ")
+       print A[fact(n)%17]
+ 
+     For n >= 13, this currently raises OverflowError (unless the user
+     enters a trailing 'L' as part of their input), even though the
+     calculated index would always be in range(17).  With the new
+     approach this code will do the right thing: the index will be
+     calculated as a long int, but its value will be in range.
+ 
+ 
  Open Issues