Collin Winter wrote:
> 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.
The Type Error is actually referring to the type of 'foo' - the code is
clearly expecting it to be something with a different __call__ signature.
However, for things like functions, there's nothing wrong with the type of the
supplied object. For functions, the problem is actually a Value Error, in that
the signature of that particular function *instance* is wrong.
I don't really have a preference here - the current error is a little obscure,
but I'm not sure fixing it is worth the effort of adding a new exception type.
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
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