Skip to content

Commit 6d2b735

Browse files
committed
Review actions
1 parent 6f35125 commit 6d2b735

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/iris/config.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

lib/iris/tests/unit/config/test_NetCDF.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_bad_value(self):
4444
warnings.simplefilter('always')
4545
iris.config.netcdf.conventions_override = bad_value
4646
self.assertFalse(iris.config.netcdf.conventions_override)
47-
exp_wmsg = 'Attempting to set bad value {!r}'.format(bad_value)
47+
exp_wmsg = 'Attempting to set invalid value {!r}'.format(bad_value)
4848
six.assertRegex(self, str(w[0].message), exp_wmsg)
4949

5050
def test__contextmgr(self):

0 commit comments

Comments
 (0)