Python 2.5: wrong number of arguments given in TypeError for function argument aggregation (dictionary input vs the norm)

mark floyd emfloyd2 at gmail.com
Thu Oct 30 23:49:00 CET 2008


I was doing some testing with the different ways to pass arguments into
functions and ran into what looks like a bug.

Given function,

def foo(a,b,c):
    print a
    print b
    print c

# Call function with named parameter list, leaving 'b' out
foo(a=1, c=3)

Traceback (most recent call last):
  File "aggregate.py", line 13, in <module>
    foo(a=1, c=3)
TypeError: foo() takes exactly 3 arguments (2 given)

# Call function with dictionary for parameter list... leaving 'c' out of the
dictionary
yarg = {'a': 111,  'b': 222}
foo(**yarg)

Traceback (most recent call last):
  File "aggregate.py", line 17, in <module>
    foo(**yarg)
TypeError: foo() takes exactly 3 non-keyword arguments (2 given)


# Call function with dictionary for parameter list... leaving 'b' out of the
dictionary

yarg = {'a': 111,  'c': 333}
foo(**yarg)

Traceback (most recent call last):
  File "aggregate.py", line 17, in <module>
    foo(**yarg)
TypeError: foo() takes exactly 3 non-keyword arguments (1 given)

It seems like the interpreter craps out too early when you leave 'b' out of
the input dictionary... and it reports the incorrect number of arguments
given (I would expect to see '2 given')

We've tested this locally using Python 2.5, Debian Etch 32-bit installation

Thanks,

- Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081030/a05c3ca5/attachment.html>


More information about the Python-list mailing list