@@ -489,14 +489,19 @@ class Either(TraitType):
489
489
490
490
def __init__ (self , * traits , ** metadata ):
491
491
"""Create a trait whose value can be any of of a specified list of traits."""
492
- metadata [ 'alternatives' ] = tuple (trait_from (t ) for t in traits )
492
+ _either_traits = tuple (trait_from (t ) for t in traits )
493
493
self .trait_maker = _TraitMaker (
494
494
metadata .pop ("default" , None ), * traits , ** metadata )
495
+ self .either_traits = _either_traits
495
496
496
497
def as_ctrait (self ):
497
498
"""Return a CTrait corresponding to the trait defined by this class."""
498
499
return self .trait_maker .as_ctrait ()
499
500
501
+ def inner_traits (self ):
502
+ """Return the *inner trait* (or traits) for this trait."""
503
+ return self .either_traits
504
+
500
505
501
506
traits .Tuple = Tuple
502
507
traits .Either = Either
@@ -550,14 +555,14 @@ def _recurse_on_path_traits(func, thistrait, value, cwd):
550
555
elif thistrait .is_trait_type (Tuple ):
551
556
value = tuple ([_recurse_on_path_traits (func , subtrait , v , cwd )
552
557
for subtrait , v in zip (thistrait .inner_traits , value )])
553
- elif thistrait .alternatives :
558
+ elif thistrait .is_trait_type ( Either ) :
554
559
is_str = [f .is_trait_type ((traits .String , traits .BaseStr , traits .BaseBytes , Str ))
555
- for f in thistrait .alternatives ]
560
+ for f in thistrait .inner_traits ]
556
561
if any (is_str ) and isinstance (value , (bytes , str )) and not value .startswith ('/' ):
557
562
return value
558
- is_basepath = [f .is_trait_type (BasePath ) for f in thistrait .alternatives ]
563
+ is_basepath = [f .is_trait_type (BasePath ) for f in thistrait .inner_traits ]
559
564
if any (is_basepath ):
560
- subtrait = thistrait .alternatives [is_basepath .index (True )]
565
+ subtrait = thistrait .inner_traits [is_basepath .index (True )]
561
566
value = _recurse_on_path_traits (func , subtrait , value , cwd )
562
567
return value
563
568
0 commit comments