kwarg handling

In responding to an inquiry about an exception raised when using

"plot(..., markerfacecolor=None)"

(http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg07627.html)

I made a small change to avoid the problem. My question is, should the following be raised to a general principle, to be followed with at most rare exceptions?

Whenever there is a setter for an artist property, that setter should be used in the artist __init__method, with no additional logic, so that a kwarg setting in __init__ has the same effect as calling the artist update method with that kwarg.

This affects plot in particular because the line property kwargs are not used via the __init__ method but are applied by calling update(). Typically there is some logic along the lines

if kw is None:
     kw = defkw

and I am suggesting that this handling of None as a default should always be moved to a setter if one exists. That way, a user can always get a property back to its default value by setting it to None.

Does anyone immediately see any problem or disadvantage in this? (I have not looked through the code carefully myself, so I could easily be missing something.)

Eric

I think localizing the logic into the setters is mostly a win-win
proposition, but there are a couple of points you raised that I want
to comment on. I consider our overloading of None to mean "do the
default, use rc" something of a wart, since it would be more properly
handled with a proper object or special value, like a *class
RCDefault* instance or a string literal 'rcdefault'. The None
handling may be a wart we are committed to because of legacy code, or
it may be something we will change, but we should recognize it as a
somewhat non-intuitive wart. I say "somewhat" because None is used in
other python codes as a default sentinel for mutable keyword arguments
(eg, lists and dicts) but otherwise I do not find it terribly obvious.

The 2nd comment is that I don't find this use case compelling. Using
None in a setter to mean "restore the rc default" may be consistent
with the __init__ handling, but it is not something that anyone has
ever asked for. In fact, in the use case that prompted this fix, the
OP intended 'None' rather than None, so the fact that mpl raised on
None rather than reverting to the rc default might be considered a
feature rather than a bug.

So basically, I'm +0 on this proposal. Better than what we have, not ideal.

JDH

···

On Sat, Jul 12, 2008 at 4:31 PM, Eric Firing <efiring@...229...> wrote:

and I am suggesting that this handling of None as a default should
always be moved to a setter if one exists. That way, a user can always
get a property back to its default value by setting it to None.

Does anyone immediately see any problem or disadvantage in this? (I
have not looked through the code carefully myself, so I could easily be
missing something.)