@@ -486,14 +486,19 @@ class Either(TraitType):
486
486
487
487
def __init__ (self , * traits , ** metadata ):
488
488
"""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 )
490
490
self .trait_maker = _TraitMaker (
491
491
metadata .pop ("default" , None ), * traits , ** metadata )
492
+ self .either_traits = _either_traits
492
493
493
494
def as_ctrait (self ):
494
495
"""Return a CTrait corresponding to the trait defined by this class."""
495
496
return self .trait_maker .as_ctrait ()
496
497
498
+ def inner_traits (self ):
499
+ """Return the *inner trait* (or traits) for this trait."""
500
+ return self .either_traits
501
+
497
502
498
503
def _rebase_path (value , cwd ):
499
504
if isinstance (value , list ):
@@ -543,14 +548,14 @@ def _recurse_on_path_traits(func, thistrait, value, cwd):
543
548
elif thistrait .is_trait_type (Tuple ):
544
549
value = tuple ([_recurse_on_path_traits (func , subtrait , v , cwd )
545
550
for subtrait , v in zip (thistrait .inner_traits , value )])
546
- elif thistrait .alternatives :
551
+ elif thistrait .is_trait_type ( Either ) :
547
552
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 ]
549
554
if any (is_str ) and isinstance (value , (bytes , str )) and not value .startswith ('/' ):
550
555
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 ]
552
557
if any (is_basepath ):
553
- subtrait = thistrait .alternatives [is_basepath .index (True )]
558
+ subtrait = thistrait .inner_traits [is_basepath .index (True )]
554
559
value = _recurse_on_path_traits (func , subtrait , value , cwd )
555
560
return value
556
561
0 commit comments