Ouch, sorry, I do not even have 2.2 installed. Guess with
> that information, the whole patch becomes bogus.
> On the other hand: simpy reverting pop to get leaves you
> with the old problem: you have to drop the check for
> emptyness of kwargs since legal arguments are not removed
> after use. If, on the other hand, you remove this check,
> erraneous (p.e. misspelled) arguments are just silently
> ignored.
> Maybe, a wrapper would solve the problem? How would one
> code a replacement for pop that works on 2.2 as well?
> Probably easiest by using get and del within a
> try..except block? The wrapper could then have a clear
> note how to replace it once 2.3 becomes mandatory
> sometimes in the future.
I added a method popd to matplotlib.cbook. It should work just like
d.pop(key) but you call popd(d, key). Like pop, it accepts a default
value.
Before we reapply your patch to raise on bad kwargs, I think it's
worth getting some input if we want to raise on nonexistent keys. In
some cases, it might be desirable to be able to do, for example
legend(handles, labels, linewidth=2, fontsize=12)
From an implementation standpoint, it's easiest to implement something
like this using anonymous **kwargs, and iterate over all the handles
and text objects calling set_someprop(val) if set_someprop exists for
some object.
Ie, rather than making all the keyword args explicit and therefore
having to add explicitly add all the setters for line, text and patch
to the kwargs of Legend, which would become a maintenance problem
(duplication of properties throughout the code), one possible design
is to just put a blanket kwargs at the end and define an Artist update
method to look like (freestyle coding here...)
def update(self, **kwargs):
for key, val in kwargs.items():
func = getattr(self, 'set_'+key, None)
if func is None or not callable(func): continue
func(val)
Then we could do in the legend class
for o in lines+texts+patches: o.update(kwargs)
The downside of course is that this fails silently if the user
provides a bad kwarg. The upside is it is a very easy, clean
implementation that scales with the addition of new setters to the
underlying objects.
JDH