MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _listify_validator

Function _listify_validator

lib/matplotlib/rcsetup.py:126–162  ·  view source on GitHub ↗
(scalar_validator, allow_stringlist=False, *,
                       n=None, doc=None)

Source from the content-addressed store, hash-verified

124
125@lru_cache
126def _listify_validator(scalar_validator, allow_stringlist=False, *,
127 n=None, doc=None):
128 def f(s):
129 if isinstance(s, str):
130 try:
131 val = [scalar_validator(v.strip()) for v in s.split(',')
132 if v.strip()]
133 except Exception:
134 if allow_stringlist:
135 # Special handling for colors
136 val = _single_string_color_list(s, scalar_validator)
137 else:
138 raise
139 # Allow any ordered sequence type -- generators, np.ndarray, pd.Series
140 # -- but not sets, whose iteration order is non-deterministic.
141 elif np.iterable(s) and not isinstance(s, (set, frozenset)):
142 # The condition on this list comprehension will preserve the
143 # behavior of filtering out any empty strings (behavior was
144 # from the original validate_stringlist()), while allowing
145 # any non-string/text scalar values such as numbers and arrays.
146 val = [scalar_validator(v) for v in s
147 if not isinstance(v, str) or v]
148 else:
149 raise ValueError(
150 f"Expected str or other non-set iterable, but got {s}")
151 if n is not None and len(val) != n:
152 raise ValueError(
153 f"Expected {n} values, but there are {len(val)} values in {s}")
154 return val
155
156 try:
157 f.__name__ = f"{scalar_validator.__name__}list"
158 except AttributeError: # class instance.
159 f.__name__ = f"{type(scalar_validator).__name__}List"
160 f.__qualname__ = f.__qualname__.rsplit(".", 1)[0] + "." + f.__name__
161 f.__doc__ = doc if doc is not None else scalar_validator.__doc__
162 return f
163
164
165def validate_any(s):

Callers 4

rcsetup.pyFile · 0.85
validate_whiskersFunction · 0.85
validate_sketchFunction · 0.85

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…