>
> I suppose you meant to add a third rule
>
3) In any branch where a **kwargs -taking function does not call
> another function it forwards the **kwargs argument to, it must raise an
> error if any unrecognized kwargs are left.
>
> Note that this solution comes as a fairly significant penalty: you end up
> copying/modifying the kwargs argument *all the time*. Those are dictionary
> mutations (note that if you received a **kwargs, you cannot mutate the
> kwargs, since this is someone else's dictionary. You have to copy it).
> That's why I mentioned low/zero overhead. It would be nice to avoid.
>
I don't see why you can't modify that dictionary. It is your dictionary
in the function as you pass it along with **kwds.
sage: d
{'a': 5, 'b': 7}
sage: def foo(**kwds):
....: del kwds['a']
....: print "foo"
....:
sage: def bar(**kwds):
....: print "bar1", kwds
....: foo(**kwds)
....: print "bar2", kwds
....:
sage: bar(**d)
bar1 {'a': 5, 'b': 7}
foo
bar2 {'a': 5, 'b': 7}
sage: d
{'a': 5, 'b': 7}
So you are free to delete the keywords you care about. Moreover, I think
there is some overhead anyways from dict copying unless python is doing
some very cleaver and special handling of keyword arguments/**kwds function
input.
>
> In other suggestions: not using **kwargs is in general not really
> practical. Introducing a new keyword below now requires all levels above to
> be modified. DRY afficionado's won't approve. Plus explicitly spelling out
> all keywords loses possible advantages of passing on a **kwargs unmodified.
>
> I would take a more middle ground approach of specifying the keywords
you will use, but have a **kwargs for the rest you have to pass along.
(This might be what Jeroen was suggesting.)
Best,
Travis
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.