One of the things that's always puzzled me about Python 2.x is why any of the following raise a TypeError:
Given a function "def foo(a, b, c=None)", > foo(4) > foo(4, 5, 6, 7) > foo(4, 5, b=6) > foo(4, 5, d=6) all raise TypeErrors, as do several other classes of calling errors -- none of which have anything to do with the type of an object. This usage of TypeError is confusing. Also, "except TypeError" statements may end up accidentally hiding this class of error, making one of these situations very difficult to debug. To make it more obvious what the problem is, I propose that Python 3000 introduce an ArgumentError exception to handle these cases. The one case that I'm not sure about is this: """ >>> def foo(a, (b, c)): pass ... >>> foo(5, 6) TraceBack (most recent call last) File "<stdin>", line 1, in <module> File "<stind>", line 1, in foo TypeError: unpack non-sequence """ I can see arguments both for keeping this as a TypeError and for changing it to an ArgumentError. Since I doubt that anyone is (intentionally) trapping this particular brand of TypeErrors, it might even be feasible to make the TypeError -> ArgumentError changeover in Python 2.6. I'm more than willing to work up a PEP and patches for this if there's interest. Collin Winter _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
