[issue2516] Instance methods are misreporting the number of arguments

Alexander Belopolsky report at bugs.python.org
Fri Apr 4 17:11:05 CEST 2008


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On Thu, Apr 3, 2008 at 9:39 PM, Raymond Hettinger
<report at bugs.python.org> wrote:

> It's definitely a bug

What would you say to the following:

def f(x):
    pass
class X:
    xf = f

x = X()
x.xf(1,2)

--> TypeError: f() takes exactly 1 argument (3 given)

Is this correct?

..
>  I was hoping for something along the lines of functions raising an
>  ArgumentError (a new subclass of TypeError) that could be trapped by
>  the __call__ slot for bound methods and then reraised with a new
>  argument count.

This would be my first choice for a clean solution as well.  Since it
will require a change to the exception hierarchy, should we discuss a
modification to PEP 348 on python-dev?   I would rather finish the
patch first and then make a concrete proposal.

> The key is to find a *very* lightweight and minimal solution;

.. according to what metric?  Are you talking about the amount of code
that needs to be changed, the number of API changes or run-time
overhead?  I don't think run-time overhead is an issue: argument
errors are rarely used for flow control  because it is hard to predict
what a failed attempt to call a function would do.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2516>
__________________________________


More information about the Python-bugs-list mailing list