generated from ajparsons/python-poetry-auto-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_pipes.py
1201 lines (979 loc) · 33.3 KB
/
function_pipes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
function-pipe
Functions for pipe syntax in Python.
Version without ParamSpec for Python 3.8-3.9.
Read more at https://github.com/ajparsons/function-pipes
Licence: MIT
"""
# pylint: disable=line-too-long
from ast import (
Call,
Lambda,
Load,
Name,
NamedExpr,
NodeTransformer,
NodeVisitor,
Store,
expr,
increment_lineno,
parse,
walk,
)
from inspect import getsource
from itertools import takewhile
from textwrap import dedent
from typing import Any, Union, Callable, TypeVar, overload
T = TypeVar("T")
class _LambdaExtractor(NodeTransformer):
"""
Replace references to the lambda argument with the passed in value
"""
def __init__(
self,
_lambda: Lambda,
value: Union[expr, Call],
subsequent_value: Union[expr, Call, None] = None,
):
self._lambda = _lambda
self.arg_name = self._lambda.args.args[0].arg # type: ignore
self.visit_count = 0
self.value = value
self.subsequent_value = subsequent_value
def extract_and_replace(self):
"""
Return what the lambda does, but replaces
references to the lambda arg with
the passed in value
"""
self.visit(self._lambda.body)
return self._lambda.body
def visit_Name(self, node: Name):
"""
Replace the internal lambda arg reference with the given value
If a subsequent value given, replace all values after the first with that
This allows assigning using a walrus in the first value, and then
using that value without recalculation in the second.
"""
if node.id == self.arg_name:
if self.visit_count == 0:
self.visit_count += 1
return self.value
if self.subsequent_value:
return self.subsequent_value
else:
raise ValueError("This lambda contains multiple references to the arg")
return node
def copy_position(source: expr, destination: expr):
"""
Copy the position information from one AST node to another
"""
destination.lineno = source.lineno
destination.end_lineno = source.end_lineno
destination.col_offset = source.col_offset
destination.end_col_offset = source.end_col_offset
class _CountLambdaArgUses(NodeVisitor):
"""
Count the number of uses of the first argument in the lambda
in the lambda definition
"""
def __init__(self, _lambda: Lambda):
self._lambda = _lambda
self.arg_name = self._lambda.args.args[0].arg # type: ignore
self.uses: int = 0
def check(self) -> int:
"""
Get the number of times the arugment is referenced
"""
self.visit(self._lambda.body) # type: ignore
return self.uses
def visit_Name(self, node: Name):
"""
Increment the uses count if the name is the given arg
"""
if node.id == self.arg_name:
self.uses += 1
self.generic_visit(node)
class _PipeTransformer(NodeTransformer):
"""
A NodeTransformer that rewrites the code tree so that all references to replaced with
a set of nested function calls.
a = pipe(a,b,c,d)
becomes
a = d(c(b(a)))
This also expands lambdas so that there is no function calling overhead.
a = pipe(a,b,c,lambda x: x+1)
becomes:
a = (c(b(a))) + 1
Where there are multiple uses of the argument in a lambda,
a walrus is used to avoid duplication calculations.
a = pipe(a,b,c,lambda x: x + x + 1)
becomes:
a = (var := c(b(a))) + var + 1
"""
def visit_Call(self, node: Call) -> Any:
"""
Replace all references to the pipe function with nested function calls.
"""
if node.func.id == "pipe": # type: ignore
value = node.args[0]
funcs = node.args[1:]
# unpack the functions into nested calls
# unless the function is a lambda
# in which case, the lambda's body
# needs to be unpacked
for func in funcs:
if isinstance(func, Lambda):
arg_usage = _CountLambdaArgUses(func).check()
if arg_usage == 0:
# this will throw an error at build time rather than runtime
# but shouldn't be a surprise to typecheckers
raise ValueError("This lambda has no arguments.")
elif arg_usage == 1:
# if the lambda only uses the argument once
# can just substitute the arg in the lambda
# with the value in the loop
# e.g. a = pipe(5, lambda x: x + 1)
# becomes a = 5 + 1
value = _LambdaExtractor(func, value).extract_and_replace()
elif arg_usage > 1:
# if the lambda uses the argument more than once
# have to assign the value to a variable first
# (using a walrus)
# and then use the variable in the lambda in subsequent calls.
# e.g. a = pipe(5, lambda x: x + x + 1)
# becomes a = (var := 5) + var + 1
# NamedExpr is how := works behind the scenes.
walrus = NamedExpr(
target=Name(id="_pipe_temp_var", ctx=Store()), value=value
)
walrus.lineno = func.lineno
copy_position(func, walrus)
temp_var = Name(id="_pipe_temp_var", ctx=Load())
copy_position(func, temp_var)
value = _LambdaExtractor(
func, walrus, temp_var
).extract_and_replace()
else:
# if just a function, we're just building a nesting call chain
value = Call(func, [value], [])
copy_position(func, value)
return value # type: ignore
return self.generic_visit(node)
def fast_pipes(func: Callable[..., T]) -> Callable[..., T]:
"""
Decorator function that replaces references to pipe with
the direct equivalent of the pipe function.
"""
# This approach adapted from
# adapted from https://github.com/robinhilliard/pipes/blob/master/pipeop/__init__.py
ctx = func.__globals__
first_line_number = func.__code__.co_firstlineno
source = getsource(func)
# AST data structure representing parsed function code
tree = parse(dedent(source))
# Fix line and column numbers so that debuggers still work
increment_lineno(tree, first_line_number - 1)
source_indent = sum([1 for _ in takewhile(str.isspace, source)]) + 1
for node in walk(tree):
if hasattr(node, "col_offset"):
node.col_offset += source_indent
# Update name of function or class to compile
tree.body[0].name += "_fast_pipe" # type: ignore
# remove the pipe decorator so that we don't recursively
# call it again. The AST node for the decorator will be a
# Call if it had braces, and a Name if it had no braces.
# The location of the decorator function name in these
# nodes is slightly different.
tree.body[0].decorator_list = [ # type: ignore
d
for d in tree.body[0].decorator_list # type: ignore
if isinstance(d, Call)
and d.func.id != "fast_pipes" # type: ignore
or isinstance(d, Name)
and d.id != "fast_pipes"
]
# Apply the visit_Call transformation
tree = _PipeTransformer().visit(tree)
# now compile the AST into an altered function or class definition
try:
code = compile(
tree,
filename=(ctx["__file__"] if "__file__" in ctx else "repl"),
mode="exec",
)
except SyntaxError as e:
# The syntax is rearranged in a way that triggers a starred error correctly
# Easier to adjust the error here than figure out how to raise it properly
# in the AST visitor.
# This is a bit hacky, but it's good enough for now.
if e.msg == "can't use starred expression here" and (
e.text and "pipe(" in e.text
):
e.msg = "pipe can't take a starred expression as an argument when fast_pipes is used."
raise e
# and execute the definition in the original context so that the
# decorated function can access the same scopes as the original
exec(code, ctx)
# return the modified function or class - original is nevers called
return ctx[tree.body[0].name]
BridgeType = TypeVar("BridgeType")
InputVal = TypeVar("InputVal")
# Always overridden by the overloads but is
# self consistent in the declared function
stand_in_callable = Union[Callable[..., Any], None]
Out0 = TypeVar("Out0")
Out1 = TypeVar("Out1")
Out2 = TypeVar("Out2")
Out3 = TypeVar("Out3")
Out4 = TypeVar("Out4")
Out5 = TypeVar("Out5")
Out6 = TypeVar("Out6")
Out7 = TypeVar("Out7")
Out8 = TypeVar("Out8")
Out9 = TypeVar("Out9")
Out10 = TypeVar("Out10")
Out11 = TypeVar("Out11")
Out12 = TypeVar("Out12")
Out13 = TypeVar("Out13")
Out14 = TypeVar("Out14")
Out15 = TypeVar("Out15")
Out16 = TypeVar("Out16")
Out17 = TypeVar("Out17")
Out18 = TypeVar("Out18")
Out19 = TypeVar("Out19")
def pipe_bridge(
func: Callable[[BridgeType], Any]
) -> Callable[[BridgeType], BridgeType]:
"""
When debugging, you might want to use a function to see
the current value in the pipe, but examination functions.
may not return the value to let it continue down the chain.
This wraps the function so that it does it's job, and then
returns the original value to conitnue down the chain.
For instance:
```
bridge(rich.print)
```
Will use the rich library's print function to look at the value,
but then unlike calling `rich.print` directly in the pipe,
will return the value to let it continue.
"""
def _inner(value: BridgeType) -> BridgeType:
func(value)
return value
return _inner
@overload
def pipe(value: InputVal, op0: Callable[[InputVal], Out0], /) -> Out0:
...
@overload
def pipe(
value: InputVal, op0: Callable[[InputVal], Out0], op1: Callable[[Out0], Out1], /
) -> Out1:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
/,
) -> Out2:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
/,
) -> Out3:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
/,
) -> Out4:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
/,
) -> Out5:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
/,
) -> Out6:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
/,
) -> Out7:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
/,
) -> Out8:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
/,
) -> Out9:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
/,
) -> Out10:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
/,
) -> Out11:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
/,
) -> Out12:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
/,
) -> Out13:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
/,
) -> Out14:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
op15: Callable[[Out14], Out15],
/,
) -> Out15:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
op15: Callable[[Out14], Out15],
op16: Callable[[Out15], Out16],
/,
) -> Out16:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
op15: Callable[[Out14], Out15],
op16: Callable[[Out15], Out16],
op17: Callable[[Out16], Out17],
/,
) -> Out17:
...
@overload
def pipe(
value: InputVal,
op0: Callable[[InputVal], Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
op15: Callable[[Out14], Out15],
op16: Callable[[Out15], Out16],
op17: Callable[[Out16], Out17],
op18: Callable[[Out17], Out18],
/,
) -> Out18:
...
def pipe(value: Any, op0: stand_in_callable = None, op1: stand_in_callable = None, op2: stand_in_callable = None, op3: stand_in_callable = None, op4: stand_in_callable = None, op5: stand_in_callable = None, op6: stand_in_callable = None, op7: stand_in_callable = None, op8: stand_in_callable = None, op9: stand_in_callable = None, op10: stand_in_callable = None, op11: stand_in_callable = None, op12: stand_in_callable = None, op13: stand_in_callable = None, op14: stand_in_callable = None, op15: stand_in_callable = None, op16: stand_in_callable = None, op17: stand_in_callable = None, op18: stand_in_callable = None, op19: stand_in_callable = None, /) -> Any: # type: ignore
"""
Pipe takes up to 20 functions and applies them to a value.
"""
if not op0:
return value # fmt: skip
elif not op1:
return op0(value) # fmt: skip
elif not op2:
return op1(op0(value)) # fmt: skip
elif not op3:
return op2(op1(op0(value))) # fmt: skip
elif not op4:
return op3(op2(op1(op0(value)))) # fmt: skip
elif not op5:
return op4(op3(op2(op1(op0(value))))) # fmt: skip
elif not op6:
return op5(op4(op3(op2(op1(op0(value)))))) # fmt: skip
elif not op7:
return op6(op5(op4(op3(op2(op1(op0(value))))))) # fmt: skip
elif not op8:
return op7(op6(op5(op4(op3(op2(op1(op0(value)))))))) # fmt: skip
elif not op9:
return op8(op7(op6(op5(op4(op3(op2(op1(op0(value))))))))) # fmt: skip
elif not op10:
return op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value)))))))))) # fmt: skip
elif not op11:
return op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value))))))))))) # fmt: skip
elif not op12:
return op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value)))))))))))) # fmt: skip
elif not op13:
return op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value))))))))))))) # fmt: skip
elif not op14:
return op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value)))))))))))))) # fmt: skip
elif not op15:
return op14(op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value))))))))))))))) # fmt: skip
elif not op16:
return op15(op14(op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value)))))))))))))))) # fmt: skip
elif not op17:
return op16(op15(op14(op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value))))))))))))))))) # fmt: skip
elif not op18:
return op17(op16(op15(op14(op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value)))))))))))))))))) # fmt: skip
elif not op19:
return op18(op17(op16(op15(op14(op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value))))))))))))))))))) # fmt: skip
else:
return op19(op18(op17(op16(op15(op14(op13(op12(op11(op10(op9(op8(op7(op6(op5(op4(op3(op2(op1(op0(value)))))))))))))))))))) # fmt: skip
@overload
def pipeline(op0: Callable[..., Out0], /) -> Callable[..., Out0]:
...
@overload
def pipeline(
op0: Callable[..., Out0], op1: Callable[[Out0], Out1], /
) -> Callable[..., Out1]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
/,
) -> Callable[..., Out2]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
/,
) -> Callable[..., Out3]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
/,
) -> Callable[..., Out4]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
/,
) -> Callable[..., Out5]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
/,
) -> Callable[..., Out6]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
/,
) -> Callable[..., Out7]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
/,
) -> Callable[..., Out8]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
/,
) -> Callable[..., Out9]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
/,
) -> Callable[..., Out10]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
/,
) -> Callable[..., Out11]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
/,
) -> Callable[..., Out12]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
/,
) -> Callable[..., Out13]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
/,
) -> Callable[..., Out14]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
op15: Callable[[Out14], Out15],
/,
) -> Callable[..., Out15]:
...
@overload
def pipeline(
op0: Callable[..., Out0],
op1: Callable[[Out0], Out1],
op2: Callable[[Out1], Out2],
op3: Callable[[Out2], Out3],
op4: Callable[[Out3], Out4],
op5: Callable[[Out4], Out5],
op6: Callable[[Out5], Out6],
op7: Callable[[Out6], Out7],
op8: Callable[[Out7], Out8],
op9: Callable[[Out8], Out9],
op10: Callable[[Out9], Out10],
op11: Callable[[Out10], Out11],
op12: Callable[[Out11], Out12],
op13: Callable[[Out12], Out13],
op14: Callable[[Out13], Out14],
op15: Callable[[Out14], Out15],
op16: Callable[[Out15], Out16],
/,
) -> Callable[..., Out16]:
...
@overload
def pipeline(
op0: Callable[..., Out0],