[Python-3000] Changing function-related TypeErrors
Guido van Rossum
guido at python.org
Sat May 6 17:29:57 CEST 2006
On 5/6/06, Collin Winter <collinw at gmail.com> wrote:
> On 5/5/06, Guido van Rossum <guido at python.org> wrote:
> > I'm not sure it's worth distinguishing call signature errors from
> > other type errors; there's already a gray area where sometimes a
> > TypeError is reported as an AttributeError or vice versa.
>
> I think that this way of looking at call errors is fairly divorced
> from the way programmers actually work. If you look at a call error as
> a type error (or ValueError), then you're saying that the call site
> arguments are correct -- you've simply used the wrong function. But
> what process do you go through to fix a call-site error? Do you change
> function X to match the call site or write a function with the proper
> signature that wraps function X? Of course not. You change the call
> site to match the signature.
Actually, it's symmetric. When Python issues a TypeError for 'a'+1,
which argument is wrong? It depends! The same is true in general when
the arguments don't match the function. You could have made a typo and
called a different function than you meant to call. Or it could be a
method of a different object than you expected. You could have
mis-implemented an overriding method.
Your assumption is that when you get an argument type error it's
always a bug in the call site. That's simply not true.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list