[Python-3000] PEP 3102

Arnaud Delobelle arnodel at googlemail.com
Tue Feb 19 19:45:06 CET 2008


On 19 Feb 2008, at 10:49, Nick Coghlan wrote:
[...]
>> Such obscure features warrant an obscure yet well-named decorator,  
>> not
>> an obscure syntax that's difficult to get help on.
>
> It's difficult to handle this in a decorator, as the problem that  
> occurs is the underlying function reporting duplicate definitions  
> for a parameter.
>
> >>> def f(self, **kwds):
> ...     print self, kwds
> ...
> >>> f(1, self=2)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: f() got multiple values for keyword argument 'self'
>
> There really isn't a lot a decorator can do to prevent this, unless  
> we modify function calls to permit direct assignment of the keywords  
> dictionary without unpacking it. Then it would become possible to  
> provide a decorator in functools along the lines of:
>
> def positional_only(required=1):
>    def wrap(f):
>        @wraps(f)
>        def wrapper(*args, **kwds):
>            if len(args) < required:
>                raise TypeError("Need %d positional arguments "
>                                "(%d given)" % (required, len(args)))
>            f(*args, **=kwds)
>

[...]

> We've also veered fairly far off topic for the Py3k list - further  
> ideas for positional-only argument syntax or decorators should  
> probably be kicked around on python-ideas rather than here or python- 
> dev.

For reference, here was a long thread on this on python-ideas [1].   
Several syntax options were discussed, I proposed using a decorator  
and several ways of achieving this were posted:

* by Steven Bethard [2]
* by me [3], [4]

I posted a cookbook recipe based on [4].

[1] http://mail.python.org/pipermail/python-ideas/2007-May/000704.html
[2] http://mail.python.org/pipermail/python-ideas/2007-May/000763.html
[3] http://mail.python.org/pipermail/python-ideas/2007-May/000808.html
[4] http://mail.python.org/pipermail/python-ideas/2007-May/000860.html

-- 
Arnaud



More information about the Python-3000 mailing list