|
30 | 30 | from matplotlib._enums import JoinStyle, CapStyle |
31 | 31 |
|
32 | 32 | # Don't let the original cycler collide with our validating cycler |
33 | | -from cycler import Cycler, cycler as ccycler |
| 33 | +from cycler import Cycler, concat as cconcat, cycler as ccycler |
34 | 34 |
|
35 | 35 |
|
36 | 36 | @_api.caching_module_getattr |
@@ -789,13 +789,32 @@ def _eval_cycler_expr(node): |
789 | 789 | return left * right |
790 | 790 | raise ValueError(f"Unsupported operator: {type(node.op).__name__}") |
791 | 791 | if isinstance(node, ast.Call): |
792 | | - if not (isinstance(node.func, ast.Name) and node.func.id == 'cycler'): |
793 | | - raise ValueError("only the 'cycler()' function is allowed") |
794 | | - args = [ast.literal_eval(a) for a in node.args] |
| 792 | + if not (isinstance(node.func, ast.Name) |
| 793 | + and node.func.id in ('cycler', 'concat')): |
| 794 | + raise ValueError( |
| 795 | + "only the 'cycler()' and 'concat()' functions are allowed") |
| 796 | + func = cycler if node.func.id == 'cycler' else cconcat |
| 797 | + args = [_eval_cycler_expr(a) for a in node.args] |
795 | 798 | kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in node.keywords} |
796 | | - return cycler(*args, **kwargs) |
797 | | - raise ValueError( |
798 | | - f"Unsupported expression in cycler string: {ast.dump(node)}") |
| 799 | + return func(*args, **kwargs) |
| 800 | + if isinstance(node, ast.Subscript): |
| 801 | + value = _eval_cycler_expr(node.value) |
| 802 | + sl = node.slice |
| 803 | + if isinstance(sl, ast.Slice): |
| 804 | + s = slice( |
| 805 | + ast.literal_eval(sl.lower) if sl.lower else None, |
| 806 | + ast.literal_eval(sl.upper) if sl.upper else None, |
| 807 | + ast.literal_eval(sl.step) if sl.step else None, |
| 808 | + ) |
| 809 | + return value[s] |
| 810 | + raise ValueError("only slicing is supported, not indexing") |
| 811 | + # Allow literal values (int, strings, lists, tuples) as arguments |
| 812 | + # to cycler() and concat(). |
| 813 | + try: |
| 814 | + return ast.literal_eval(node) |
| 815 | + except (ValueError, TypeError): |
| 816 | + raise ValueError( |
| 817 | + f"Unsupported expression in cycler string: {ast.dump(node)}") |
799 | 818 |
|
800 | 819 |
|
801 | 820 | # A validator dedicated to the named legend loc |
|
0 commit comments