[Python-Dev] Reasons behind misleading TypeError message when passing the wrong number of arguments to a method (original) (raw)

Michael Urman murman at gmail.com
Fri May 21 14:25:33 CEST 2010


On Thu, May 20, 2010 at 22:54, Steven D'Aprano <steve at pearwood.info> wrote:

This is misleading, since C().method is a bound method which takes one argument, x, not two. I find myself wishing that Python distinguished between ArgumentError and other TypeErrors, so that the method wrapper of bound methods could simply catch ArgumentError and subtract 1 from each argument count.

But how exactly could it distinguish between various levels of call nesting?

class C:
    def a(self, i): return self.b(i)
    def b(self, j): return self.c(j)
    def c(self, k): return self.a()

What should C.a(), C().a(), and C().a(1) each yield? Does it change if c(self, k) calls C.a(self)?

-- Michael Urman



More information about the Python-Dev mailing list