@@ -2268,21 +2268,38 @@ def type_name(tp):
22682268 type_name (type (v ))))
22692269
22702270
2271- def _check_in_list (_values , ** kwargs ):
2271+ def _check_in_list (_values , * , _print_supported_values = True , * *kwargs ):
22722272 """
2273- For each *key, value* pair in *kwargs*, check that *value* is in *_values*;
2274- if not, raise an appropriate ValueError.
2273+ For each *key, value* pair in *kwargs*, check that *value* is in *_values*.
2274+
2275+ Parameters
2276+ ----------
2277+ _values : iterable
2278+ Sequence of values to check on.
2279+ _print_supported_values : bool, default: True
2280+ Whether to print *_values* when raising ValueError.
2281+ **kwargs : dict
2282+ *key, value* pairs as keyword arguments to find in *_values*.
2283+
2284+ Raises
2285+ ------
2286+ ValueError
2287+ If any *value* in *kwargs* is not found in *_values*.
22752288
22762289 Examples
22772290 --------
22782291 >>> cbook._check_in_list(["foo", "bar"], arg=arg, other_arg=other_arg)
22792292 """
22802293 values = _values
2281- for k , v in kwargs .items ():
2282- if v not in values :
2283- raise ValueError (
2284- "{!r} is not a valid value for {}; supported values are {}"
2285- .format (v , k , ', ' .join (map (repr , values ))))
2294+ for key , val in kwargs .items ():
2295+ if val not in values :
2296+ if _print_supported_values :
2297+ raise ValueError (
2298+ f"{ val !r} is not a valid value for { key } ; "
2299+ f"supported values are { ', ' .join (map (repr , values ))} " )
2300+ else :
2301+ raise ValueError (
2302+ f"{ val !r} is not a valid value for { key } " )
22862303
22872304
22882305def _check_shape (_shape , ** kwargs ):
0 commit comments