Issue 1412580: locale.format gives wrong exception on some erroneous input (original) (raw)
using '2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]' on WinXpPro SP2
locale.format(formatString, val, grouping) when passed a formatString of the wrong type, ought to raise a TypeError (as some erroneous input does)
Example: locale.format(2.3, 2.3) passes through AttributeError ("float has no attribute 'split'").
I thought perhaps the body of the method should be wrapped in a try:except block, and if any error is caught, then the arguments should be rigorously tested for type and lucid exceptions raised. See attachment for suggestion (with tests).
I'm not clear whether if the format string is erroneous (bad syntax, or has too many/no %-s, the raised error should be ValueError (contractually correct) or conceivably whatever StringInterpolation raises (parallelism). I've put tests for both in - currently ValueError wins.