[Python-ideas] Improving this? - foo() takes at least 6 arguments (6 given)

Giampaolo Rodolà g.rodola at gmail.com
Mon Sep 5 11:36:28 CEST 2011


2011/9/3 Mark Dickinson <dickinsm at gmail.com>:
> On Sat, Sep 3, 2011 at 9:59 AM, Eli Stevens (Gmail)
> <wickedgrey at gmail.com> wrote:
>> On Thu, Sep 1, 2011 at 10:19 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
>>>> 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.."
>>>
>>> How did you get this?
>>
>> Having seen this bite someone recently, I have an example readily at hand:
>>
>>>>> def f(a,b,c,d=None): pass
>> ...
>>>>> f(1,2,d=4)
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> TypeError: f() takes at least 3 arguments (3 given)
>
> Isn't this already fixed for Python 3.3?
>
> Python 3.3.0a0 (default:a8748022504f, Sep  2 2011, 12:32:36)
> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> def f(a, b, c, d=None): pass
> ...
> [63593 refs]
>>>> f(1, 2, d=4)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: f() missing 1 required positional argument: 'c'
> [63624 refs]
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>

This is a very good improvement I wasn't aware of!
Glad to see that.

Regards,

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/



More information about the Python-ideas mailing list