keyword-only arguments and varags
Currently, def f(*, kw, **kwargs): pass is valid syntax, but def f(*args, *, kw): pass is not. I don't see any mention of it in the PEP but perhaps there is a good reason this isn't allowed. It seems to be perfectly well-defined to me. -- Regards, Benjamin
On Sun, Jun 5, 2011 at 11:45 AM, Benjamin Peterson <benjamin@python.org> wrote:
Currently,
def f(*, kw, **kwargs): pass
is valid syntax, but
def f(*args, *, kw): pass
is not.
I don't see any mention of it in the PEP but perhaps there is a good reason this isn't allowed. It seems to be perfectly well-defined to me.
Really? There's two single-stars there. One says "accept arbitrary positional arguments and place them in a tuple named args", the second says "don't accept any more positional args". You can't have it both ways, so the compiler complains. The following works fine to mix keyword-only arguments with arbitrary positional arguments, so I don't see a problem: def f(*args, kw): pass Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
2011/6/5 Nick Coghlan <ncoghlan@gmail.com>:
On Sun, Jun 5, 2011 at 11:45 AM, Benjamin Peterson <benjamin@python.org> wrote:
Currently,
def f(*, kw, **kwargs): pass
is valid syntax, but
def f(*args, *, kw): pass
is not.
I don't see any mention of it in the PEP but perhaps there is a good reason this isn't allowed. It seems to be perfectly well-defined to me.
Really? There's two single-stars there. One says "accept arbitrary positional arguments and place them in a tuple named args", the second says "don't accept any more positional args". You can't have it both ways, so the compiler complains.
Thank you. More proof I shouldn't write emails after 22:00 local time.
The following works fine to mix keyword-only arguments with arbitrary positional arguments, so I don't see a problem:
def f(*args, kw): pass
Move along, nothing to see here... -- Regards, Benjamin
participants (2)
-
Benjamin Peterson -
Nick Coghlan