Skip to content

Commit 18dcb6b

Browse files
committed
fix(Either): better implementation that allows make specs
1 parent 96b7772 commit 18dcb6b

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
traits.Tuple = Tuple
499504
traits.Either = Either
@@ -547,14 +552,14 @@ def _recurse_on_path_traits(func, thistrait, value, cwd):
547552
elif thistrait.is_trait_type(Tuple):
548553
value = tuple([_recurse_on_path_traits(func, subtrait, v, cwd)
549554
for subtrait, v in zip(thistrait.inner_traits, value)])
550-
elif thistrait.alternatives:
555+
elif thistrait.is_trait_type(Either):
551556
is_str = [f.is_trait_type((traits.String, traits.BaseStr, traits.BaseBytes, Str))
552-
for f in thistrait.alternatives]
557+
for f in thistrait.inner_traits]
553558
if any(is_str) and isinstance(value, (bytes, str)) and not value.startswith('/'):
554559
return value
555-
is_basepath = [f.is_trait_type(BasePath) for f in thistrait.alternatives]
560+
is_basepath = [f.is_trait_type(BasePath) for f in thistrait.inner_traits]
556561
if any(is_basepath):
557-
subtrait = thistrait.alternatives[is_basepath.index(True)]
562+
subtrait = thistrait.inner_traits[is_basepath.index(True)]
558563
value = _recurse_on_path_traits(func, subtrait, value, cwd)
559564
return value
560565

0 commit comments

Comments
 (0)