[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
- Previous message (by thread): [Python-Dev] Let's change to C API!
- Next message (by thread): [Python-Dev] Error message for wrong number of arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): [Python-Dev] Let's change to C API!
- Next message (by thread): [Python-Dev] Error message for wrong number of arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]