[New-bugs-announce] [issue5383] Allow intermixing of keyword arguments and vargarg arguments
David Kerkeslager
report at bugs.python.org
Fri Feb 27 17:45:52 CET 2009
New submission from David Kerkeslager <david.kerkeslager at gmail.com>:
This problem arose in this thread:
http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=11606
Basically, we have the following function which will generate an XHTML
node:
def xhtmlNode(tag, *content, **attr):...
If we call:
xhtmlNode('div',id='sidebar','Hello, world')
... it should generate the xhtml:
<div id='sidebar'>Hello, world</div>
However, this isn't possible because the keyword argument isn't allowed
to come before the 'vararg' argument. We could do this:
xhtmlNode('div','Hello, world',id='sidebar')
... but this would not have symmetry with the generated xhtml and
therefore complicates the code. The solution, in my opinion, is to
allow varargs to be intermixed with keyword args. The above real-world
example shows a use-case for this more flexible functionality.
If the following rules apply, there shouldn't be any issues:
1. Positional arguments must be in their position (positional arguments
must come before all 'vararg' arguments and keyword arguments).
2. Varargs come in the order in which they are received, ignoring any
keyword arguments that are intermixed.
3. Keyword arguments order doesn't matter (a dictionary isn't ordered).
They can be intermixed with varargs.
Thus the following call:
xhtmlNode('div',id='sidebar',style='width:100px;float:left;','Hello,worl
d',xhtmlNode('p','Hello, world'))
... would result in the following html:
<div id='sidebar' style='width:100px;float:left;'> Hello, world
<p>Hello, world</p></div>
----------
messages: 82839
nosy: Imagist
severity: normal
status: open
title: Allow intermixing of keyword arguments and vargarg arguments
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5383>
_______________________________________
More information about the New-bugs-announce
mailing list