@@ -178,21 +178,21 @@ def __init__(self, conventions_override=None):
178178 If `False` (the default), specifies that Iris should set the
179179 CF Conventions version when saving cubes as NetCDF files.
180180 If `True`, specifies that the cubes being saved to NetCDF should
181- set the cf conventions version for the saved NetCDF files.
181+ set the CF Conventions version for the saved NetCDF files.
182182
183183 Example usages:
184184
185185 * Specify, for the lifetime of the session, that we want all cubes
186186 written to NetCDF to define their own CF Conventions versions::
187187
188- iris.options .netcdf.conventions_override = True
188+ iris.config .netcdf.conventions_override = True
189189 iris.save('my_cube', 'my_dataset.nc')
190190 iris.save('my_second_cube', 'my_second_dataset.nc')
191191
192192 * Specify, with a context manager, that we want a cube written to
193193 NetCDF to define its own CF Conventions version::
194194
195- with iris.options .netcdf.context(conventions_override=True):
195+ with iris.config .netcdf.context(conventions_override=True):
196196 iris.save('my_cube', 'my_dataset.nc')
197197
198198 """
@@ -202,15 +202,19 @@ def __init__(self, conventions_override=None):
202202 # Now set specific values.
203203 setattr (self , 'conventions_override' , conventions_override )
204204
205- def __str__ (self ):
206- msg = 'NetCDF options: conventions_override={}.'
207- return msg .format (self .conventions_override )
205+ def __repr__ (self ):
206+ msg = 'NetCDF options: {}.'
207+ # Automatically populate with all currently accepted kwargs.
208+ options = ['{}={}' .format (k , v )
209+ for k , v in six .iteritems (self .__dict__ )]
210+ joined = ', ' .join (options )
211+ return msg .format (joined )
208212
209213 def __setattr__ (self , name , value ):
210214 if name not in self .__dict__ :
211215 # Can't add new names.
212- msg = "'Option' object has no attribute {!r}" . format ( name )
213- raise AttributeError (msg )
216+ msg = 'Cannot set option {!r} for {} configuration.'
217+ raise AttributeError (msg . format ( name , self . __class__ . __name__ ) )
214218 if value is None :
215219 # Set an unset value to the name's default.
216220 value = self ._defaults_dict [name ]['default' ]
@@ -220,14 +224,15 @@ def __setattr__(self, name, value):
220224 # anything goes.
221225 if value not in self ._defaults_dict [name ]['options' ]:
222226 good_value = self ._defaults_dict [name ]['default' ]
223- wmsg = ('Attempting to set bad value {!r} for attribute {!r}. '
224- 'Defaulting to {!r}.' )
227+ wmsg = ('Attempting to set invalid value {!r} for '
228+ 'attribute {!r}. Defaulting to {!r}.' )
225229 warnings .warn (wmsg .format (value , name , good_value ))
226230 value = good_value
227231 self .__dict__ [name ] = value
228232
229233 @property
230234 def _defaults_dict (self ):
235+ # Set this as a property so that it isn't added to `self.__dict__`.
231236 return {'conventions_override' : {'default' : False ,
232237 'options' : [True , False ]},
233238 }
0 commit comments