Darren Dale wrote: > I've been thinking a bit about rcParams and validation. It looks like values > are currently only validated when matplolibrc is read, during the call to > rc_params. What if we define a new class (RcParams), derived from dict, which > has as an attribute, a dict, called validate. We could override __setitem__ > such that > > rcParams['font.size'] = 12 > > validates the value 12 by first calling validate_float, which is referenced > in > the validate attribute: > > def __setitem__(self, i='font.size', val=12) > try: > self.validate[i](val) > dict.__setitem__(self, i, val) > except KeyError: > raise (or warning), bad value > > the validation dict and default properties would be populated during the > initial call to rc_params(), when the defaultParams dict is interpretted. > Thereafter, any attempt to set a parameter, either directly using > rcParams[i]=j or indirectly using rc(), will benefit from validation. The > behavior would otherwise be unchanged, I think. Any comments or objections? >
I agree with John that the basic idea of validating rc keys and values regardless of whether they are set directly or via rc() is an important improvement to make. I think I understand the general idea of your proposed implementation. It looks like it could be done quite quickly and easily with no disruption elsewhere in the code. Alternative approaches that have been mentioned in the past involve properties or traits; but your proposed implementation may actually be cleaner, simpler, and more maintainable for present purposes. Have you compared alternatives? Have you looked at examples/rc_traits.py? (Or did you write it? I don't recall for sure, but I think John wrote it after one of our earlier discussions of traits/properties/neither.) Eric ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel