[Python-ideas] Positional only arguments

Steven Bethard steven.bethard at gmail.com
Tue May 22 01:07:06 CEST 2007


On 5/21/07, Aaron Brady <castironpi at comcast.net> wrote:
> Question on it, the example.  Is this not a feature of all UserDict
> subclasses?  Yet we have that anyway.
>
> >>> from UserDict import *
> >>> class C(UserDict):
> ...     pass
> ...
> >>> c= C( a=1, b=2 )
> >>> print c
> {'a': 1, 'b': 2}
> >>> c.update( self=3 )
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: update() got multiple values for keyword argument 'self'

Yes, it's a bug still present in UserDict. Using the @positional_only
decorator I posted in a separate thread, we can make it work
correctly::

    >>> class C(object):
    ...     @positional_only
    ...     def __init__(self, container=None, _kwargs=None):
    ...         print container, _kwargs
    ...
    >>> C(self=1, container=2)
    None {'self': 1, 'container': 2}

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy



More information about the Python-ideas mailing list