@@ -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
traits .Tuple = Tuple
499
504
traits .Either = Either
@@ -547,14 +552,14 @@ def _recurse_on_path_traits(func, thistrait, value, cwd):
547
552
elif thistrait .is_trait_type (Tuple ):
548
553
value = tuple ([_recurse_on_path_traits (func , subtrait , v , cwd )
549
554
for subtrait , v in zip (thistrait .inner_traits , value )])
550
- elif thistrait .alternatives :
555
+ elif thistrait .is_trait_type ( Either ) :
551
556
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 ]
553
558
if any (is_str ) and isinstance (value , (bytes , str )) and not value .startswith ('/' ):
554
559
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 ]
556
561
if any (is_basepath ):
557
- subtrait = thistrait .alternatives [is_basepath .index (True )]
562
+ subtrait = thistrait .inner_traits [is_basepath .index (True )]
558
563
value = _recurse_on_path_traits (func , subtrait , value , cwd )
559
564
return value
560
565
0 commit comments