Greg Ewing wrote:
Steven Bethard wrote:

py> def defaultdict(*args, **kwargs):
...     defaultfactory, args = args[0], args[1:]


which can be written more succinctly as

  def defaultdict(defaultfactory, *args, **kwargs):
    ...

Not if you want to allow the defaultfactory to be called with a keyword argument 'defaultfactory'. Compare my code:


py> def defaultdict(*args, **kwargs):
...     defaultfactory, args = args[0], args[1:]
...     print defaultfactory, args, kwargs
...
py> defaultdict(dict, defaultfactory=True)
<type 'dict'> () {'defaultfactory': True}

with the code you suggested:

py> def defaultdict(defaultfactory, *args, **kwargs):
... print defaultfactory, args, kwargs
...
py> defaultdict(dict, defaultfactory=True)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: defaultdict() got multiple values for keyword argument 'defaultfactory'


Uncommon, sure, but I'd rather not rule it out if there's no need to.

STeVe
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to