| 678 | |
| 679 | @memoize |
| 680 | def _expander(where): |
| 681 | if not where: |
| 682 | |
| 683 | def expand(seq, val): |
| 684 | return seq |
| 685 | |
| 686 | return expand |
| 687 | else: |
| 688 | decl = """def expand(seq, val): |
| 689 | return ({left}) + tuple({right}) |
| 690 | """ |
| 691 | left = [] |
| 692 | j = 0 |
| 693 | for i in range(max(where) + 1): |
| 694 | if i in where: |
| 695 | left.append("val, ") |
| 696 | else: |
| 697 | left.append(f"seq[{j}], ") |
| 698 | j += 1 |
| 699 | right = f"seq[{j}:]" |
| 700 | left = "".join(left) |
| 701 | decl = decl.format(**locals()) |
| 702 | ns = {} |
| 703 | exec(compile(decl, "<dynamic>", "exec"), ns, ns) |
| 704 | return ns["expand"] |
| 705 | |
| 706 | |
| 707 | def expander(where): |