14
14
"""
15
15
16
16
import ast
17
+ from collections .abc import Iterable
17
18
from functools import lru_cache , reduce
18
19
from numbers import Real
19
20
import operator
@@ -97,10 +98,6 @@ def f(s):
97
98
val = [scalar_validator (v .strip ()) for v in s if v .strip ()]
98
99
else :
99
100
raise
100
- elif isinstance (s , dict ):
101
- # assume dict is a value in the iterator and not the iterator
102
- # since iterating over dict only iterates over keys
103
- val = [scalar_validator (s )]
104
101
# Allow any ordered sequence type -- generators, np.ndarray, pd.Series
105
102
# -- but not sets, whose iteration order is non-deterministic.
106
103
elif np .iterable (s ) and not isinstance (s , (set , frozenset )):
@@ -129,7 +126,6 @@ def f(s):
129
126
130
127
def validate_any (s ):
131
128
return s
132
-
133
129
validate_anylist = _listify_validator (validate_any )
134
130
135
131
@@ -574,11 +570,13 @@ def validate_path_effects(s):
574
570
if not s :
575
571
return []
576
572
577
- if isinstance (s , str ) and s .startswith ("(" ):
573
+ if isinstance (s , str ) and s .strip (). startswith ("(" ):
578
574
s = ast .literal_eval (s )
579
-
580
- if not isinstance (s , list ): #string tuple list mostly
581
- s = [s ]
575
+ s = [s ] if isinstance (s [0 ], str ) else s # cast to list for the 1 tuple case
576
+ elif isinstance (s , Iterable ):
577
+ pass #validate list elements in the for loop to allow for mixed list
578
+ else :
579
+ ValueError ("Expected a list of patheffects functions or (funcname, {**kwargs}) tuples" )
582
580
583
581
_validate_name = ValidateInStrings ("path.effects" ,
584
582
["Normal" ,
@@ -590,20 +588,19 @@ def validate_path_effects(s):
590
588
"withSimplePatchShadow" ,
591
589
"withStroke" ,
592
590
"withTickedStroke" ])
591
+
592
+
593
593
path_effects = []
594
594
595
595
for pe in s :
596
596
#patheffects objects
597
- if getattr (pe , '__module__' , "" ) == 'matplotlib.patheffects' :
597
+ if isinstance (pe , tuple ):
598
+ path_effects .append ((_validate_name (pe [0 ]),
599
+ {} if len (pe )< 2 else pe [1 ]))
600
+ elif getattr (pe , '__module__' , "" ) == 'matplotlib.patheffects' :
598
601
path_effects .append (pe )
599
- continue
600
-
601
- if not isinstance (pe , (tuple )):
602
- raise ValueError ("Expected a list of tuples of the form: ('function name', {**kwargs})" )
603
-
604
- if len (pe ) == 1 :
605
- pe == (pe [0 ], {})
606
- path_effects .append ((_validate_name (pe [0 ]), pe [1 ]))
602
+ else :
603
+ raise ValueError (f'Invalid entry for path.effects: { pe } ' )
607
604
608
605
609
606
return path_effects
0 commit comments