[Python-Dev] Error message for wrong number of arguments (original) (raw)

Jeroen Demeyer J.Demeyer at UGent.be
Mon Jul 30 08:12:22 EDT 2018


Hello,

I noticed an inconsistency in the error messages for the number of arguments to a method call. For Python methods, the "self" argument is counted. For built-in methods, the "self" argument is not counted:

class mylist(list): ... def append(self, val): super().append(val)

f = list().append f(1,2) Traceback (most recent call last): File "", line 1, in TypeError: append() takes exactly one argument (2 given)

g = mylist().append g(1,2) Traceback (most recent call last): File "", line 1, in TypeError: append() takes 2 positional arguments but 3 were given

I think it has been argued before that it's a feature that self is counted. So I consider the error message for list().append a bug. This is one of the many oddities I noticed while working on improving built-in functions.

Would you agree to change the error message for built-in methods to be closer to Python methods?

Jeroen.



More information about the Python-Dev mailing list