Skip to content

Commit 24a29d9

Browse files
committed
fix(Either): better implementation that allows make specs
1 parent 969d7b0 commit 24a29d9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

nipype/interfaces/base/traits_extension.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,19 @@ class Either(TraitType):
486486

487487
def __init__(self, *traits, **metadata):
488488
"""Create a trait whose value can be any of of a specified list of traits."""
489-
metadata['alternatives'] = tuple(trait_from(t) for t in traits)
489+
_either_traits = tuple(trait_from(t) for t in traits)
490490
self.trait_maker = _TraitMaker(
491491
metadata.pop("default", None), *traits, **metadata)
492+
self.either_traits = _either_traits
492493

493494
def as_ctrait(self):
494495
"""Return a CTrait corresponding to the trait defined by this class."""
495496
return self.trait_maker.as_ctrait()
496497

498+
def inner_traits(self):
499+
"""Return the *inner trait* (or traits) for this trait."""
500+
return self.either_traits
501+
497502

498503
def _rebase_path(value, cwd):
499504
if isinstance(value, list):
@@ -543,14 +548,14 @@ def _recurse_on_path_traits(func, thistrait, value, cwd):
543548
elif thistrait.is_trait_type(Tuple):
544549
value = tuple([_recurse_on_path_traits(func, subtrait, v, cwd)
545550
for subtrait, v in zip(thistrait.inner_traits, value)])
546-
elif thistrait.alternatives:
551+
elif thistrait.is_trait_type(Either):
547552
is_str = [f.is_trait_type((traits.String, traits.BaseStr, traits.BaseBytes, Str))
548-
for f in thistrait.alternatives]
553+
for f in thistrait.inner_traits]
549554
if any(is_str) and isinstance(value, (bytes, str)) and not value.startswith('/'):
550555
return value
551-
is_basepath = [f.is_trait_type(BasePath) for f in thistrait.alternatives]
556+
is_basepath = [f.is_trait_type(BasePath) for f in thistrait.inner_traits]
552557
if any(is_basepath):
553-
subtrait = thistrait.alternatives[is_basepath.index(True)]
558+
subtrait = thistrait.inner_traits[is_basepath.index(True)]
554559
value = _recurse_on_path_traits(func, subtrait, value, cwd)
555560
return value
556561

0 commit comments

Comments
 (0)