A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-July/154831.html below:

[Python-Dev] Error message for wrong number of arguments

[Python-Dev] Error message for wrong number of argumentsJeroen 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 "<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.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4