Improving this? - foo() takes at least 6 arguments (6 given)

Hi all, Most of us who have been coding for awhile have often seen this error and understand the "self" concept. I was helping a junior colleague out and he came to me with this problem. Colleague: "So my code is apparently asking for 6 arguments and it appears that I gave it 6 arguments" Me: "Oh that - Yeah... your short one. It really wants 7.." That got me thinking and here is the post. Now while this seems simple to fix I know this isn't that simple and a healthy dose of introspection will be required. --- Steven Klass (480) 225-1112 sklass@pointcircle.com

Steven Klass wrote:
How did you get this? --> class test(object): ... def __init__(self): ... pass ... --> t = test(1) 2.5 --- Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() takes exactly 1 argument (2 given) 2.7 --- Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() takes exactly 1 argument (2 given) 3.2 --- Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() takes exactly 1 positional argument (2 given) ~Ethan~

On Thu, Sep 1, 2011 at 10:19 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
Having seen this bite someone recently, I have an example readily at hand:
The mention of self might be a bit of a red herring, since unless there's another way to generate the same error message, the error really is "f() takes at least 3 arguments (2 given, plus 1 keyword argument not counted here)". Cheers, Eli

Eli Stevens (Gmail <wickedgrey@...> writes:
Coming your way soon: Python 3.3.0a0 (default:fe0497bd7354, Sep 3 2011, 10:14:20) [GCC 4.4.5] on linux Type "help", "copyright", "credits" or "license" for more information.

Steven Klass wrote:
How did you get this? --> class test(object): ... def __init__(self): ... pass ... --> t = test(1) 2.5 --- Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() takes exactly 1 argument (2 given) 2.7 --- Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() takes exactly 1 argument (2 given) 3.2 --- Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() takes exactly 1 positional argument (2 given) ~Ethan~

On Thu, Sep 1, 2011 at 10:19 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
Having seen this bite someone recently, I have an example readily at hand:
The mention of self might be a bit of a red herring, since unless there's another way to generate the same error message, the error really is "f() takes at least 3 arguments (2 given, plus 1 keyword argument not counted here)". Cheers, Eli

Eli Stevens (Gmail <wickedgrey@...> writes:
Coming your way soon: Python 3.3.0a0 (default:fe0497bd7354, Sep 3 2011, 10:14:20) [GCC 4.4.5] on linux Type "help", "copyright", "credits" or "license" for more information.
participants (4)
-
Benjamin Peterson
-
Eli Stevens (Gmail)
-
Ethan Furman
-
Steven Klass