Error message for wrong number of arguments

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 "<stdin>", line 1, in <module> TypeError: append() takes exactly one argument (2 given)
g = mylist().append g(1,2) Traceback (most recent call last): File "<stdin>", line 1, in <module> 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.

On 30 July 2018 at 22:12, Jeroen Demeyer <J.Demeyer@ugent.be> wrote:
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?
I would, and I think it would make sense for the PEP to cite improving consistency (and reducing code duplication?) in that regard as an advantage of the PEP. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Mon, Jul 30, 2018 at 5:12 AM, Jeroen Demeyer <J.Demeyer@ugent.be> wrote:
I think it has been argued before that it's a feature that self is counted.
I suppose it is, as it's technically correct, but it's also a HUGE source of confusion, particularly for newbies. IF this is being touched anyway, is it possible for the interpreter to know when this error is generated that this is a bound method expecting a "self", rather than an arbitrary function with n parameters? In which case, it would be really nice if the error message replaced that somehow, maybe something like:
g(1,2) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: append() takes 1 positional argument in addition to the automatically added instance object -- but 2 were given in addition to the object instance.
Man -- hard to come up with good wording for that -- but SOMETHING that lets users know what they actually did wrong would be good :-) If it's not do-able, then still +1 on making builtins consistent. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (3)
-
Chris Barker
-
Jeroen Demeyer
-
Nick Coghlan