Skip to content

Commit a09aa6c

Browse files
committed
fix: deprecation warning does not reset trait to Undefined - will set new value
1 parent f058c31 commit a09aa6c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

nipype/interfaces/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def __init__(self, interface, runtime, inputs=None, outputs=None):
268268
def version(self):
269269
return self._version
270270

271+
271272
class BaseTraitedSpec(traits.HasTraits):
272273
"""Provide a few methods necessary to support nipype interface api
273274
@@ -374,7 +375,6 @@ def _deprecated_warn(self, obj, name, old, new):
374375
self.__class__.__name__.split('InputSpec')[0])
375376
msg2 = ('Will be removed or raise an error as of release %s') % \
376377
trait_spec.deprecated
377-
self.trait_set(trait_change_notify=False, **{'%s' % name: Undefined})
378378
if trait_spec.new_name:
379379
if trait_spec.new_name not in self.copyable_trait_names():
380380
raise TraitError(msg1 + ' Replacement trait %s not found' %
@@ -387,7 +387,12 @@ def _deprecated_warn(self, obj, name, old, new):
387387
raise TraitError(msg)
388388
else:
389389
warn(msg)
390-
390+
if trait_spec.new_name:
391+
warn('Unsetting %s and setting %s.' % (name,
392+
trait_spec.new_name))
393+
self.trait_set(trait_change_notify=False,
394+
**{'%s' % name: Undefined,
395+
'%s' % trait_spec.new_name: new})
391396

392397
def _hash_infile(self, adict, key):
393398
""" Inject file hashes into adict[key]"""

nipype/interfaces/tests/test_base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class DeprecationSpec1(nib.TraitedSpec):
139139
set_foo = lambda : setattr(spec_instance, 'foo', 1)
140140
yield assert_raises, nib.TraitError, set_foo
141141
class DeprecationSpec1numeric(nib.TraitedSpec):
142-
foo = nib.traits.Int(deprecated=0.1)
142+
foo = nib.traits.Int(deprecated='0.1')
143143
spec_instance = DeprecationSpec1numeric()
144144
set_foo = lambda : setattr(spec_instance, 'foo', 1)
145145
yield assert_raises, nib.TraitError, set_foo
@@ -158,6 +158,18 @@ class DeprecationSpec3(nib.TraitedSpec):
158158
except nib.TraitError:
159159
not_raised = False
160160
yield assert_true, not_raised
161+
class DeprecationSpec3(nib.TraitedSpec):
162+
foo = nib.traits.Int(deprecated='1000', new_name='bar')
163+
bar = nib.traits.Int()
164+
spec_instance = DeprecationSpec3()
165+
not_raised = True
166+
try:
167+
spec_instance.foo = 1
168+
except nib.TraitError:
169+
not_raised = False
170+
yield assert_true, not_raised
171+
yield assert_equal, spec_instance.foo, Undefined
172+
yield assert_equal, spec_instance.bar, 1
161173

162174
def checknose():
163175
"""check version of nose for known incompatability"""

0 commit comments

Comments
 (0)