@@ -201,7 +201,7 @@ def __rshift__(self, x):
201
201
stripped = strip_symbolic (x )
202
202
203
203
if isinstance (stripped , Call ):
204
- return self ._construct_pipe (MetaArg ( "_" ), self , x )
204
+ return self ._construct_pipe (self , x )
205
205
206
206
raise TypeError ()
207
207
@@ -308,9 +308,28 @@ def obj_name(self):
308
308
309
309
return None
310
310
311
- @classmethod
312
- def _construct_pipe (cls , * args ):
313
- return PipeCall (* args )
311
+ @staticmethod
312
+ def _construct_pipe (lhs , rhs ):
313
+ if isinstance (lhs , PipeCall ):
314
+ lh_args = lhs .args
315
+
316
+ # ensure we don't keep adding MetaArg to the left when
317
+ # combining two pipes
318
+ if lh_args and isinstance (lh_args [0 ], MetaArg ):
319
+ lh_args = lh_args [1 :]
320
+ else :
321
+ lh_args = [lhs ]
322
+
323
+ if isinstance (rhs , PipeCall ):
324
+ rh_args = rhs .args
325
+
326
+ # similar to above, but for rh args
327
+ if rh_args and isinstance (rh_args [0 ], MetaArg ):
328
+ rh_args = rh_args [1 :]
329
+ else :
330
+ rh_args = [rhs ]
331
+
332
+ return PipeCall (MetaArg ("_" ), * lh_args , * rh_args )
314
333
315
334
316
335
class Lazy (Call ):
@@ -674,8 +693,15 @@ class PipeCall(Call):
674
693
"""
675
694
676
695
def __init__ (self , func , * args , ** kwargs ):
677
- self .func = "__siu_pipe_call__"
678
- self .args = (func , * args )
696
+ if isinstance (func , str ) and func == "__siu_pipe_call__" :
697
+ # it was a mistake to make func the first parameter to Call
698
+ # but basically we need to catch when it is passed, so
699
+ # we can ignore it
700
+ self .func = func
701
+ self .args = args
702
+ else :
703
+ self .func = "__siu_pipe_call__"
704
+ self .args = (func , * args )
679
705
if kwargs :
680
706
raise ValueError ("Keyword arguments are not allowed." )
681
707
self .kwargs = {}
0 commit comments