From 872230b693aa4686db3da07d77f74918a537c7d8 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 14 Aug 2001 18:37:44 +0000 Subject: [PATCH] Add an example. --- pep-0237.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pep-0237.txt b/pep-0237.txt index 4a98cc4f9..317c52ccf 100644 --- a/pep-0237.txt +++ b/pep-0237.txt @@ -205,6 +205,30 @@ Transition B4. Python 3.0 (at least two years in the future). +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 We expect that these issues will be resolved over time, as more