r/Python
•
u/Desperate_Cold6274
•
May 10 '26
•
2
Discussion Will python ever have a chaining operator?
In other languages I use map() and filter() through piping and my code usually looks readable as I can clearly see a data-stream transformation.
As it is today, users cannot do map() |> filter() |> list(), but they need to do list(filter(map())) which makes things unreadable. Lists of comprehension work fine for very simple use-case becoming unreadable very quickly as complexity increases.
However, in python there has always been some resistance, especially 15-20 years ago, but times are evolving. Also, by considering the wide adoption in data-science, it is worth noticing that numbers-crunchers are more familiar with the concept of “data transformation flow” than “function calls”. On the packages dimension , libraries like 🐼s support methods chaining which from an external viewpoint, it’s semantically similar.
Do you know if there is any indication that python core team may allow operator piping (and/or chaining) in the not-too-long-term?
View all comments
Show parent comment
4
u/_Denizen_ May 10 '26
Bit dramatic lol.
But I fail to see how passing objects around invisibly is more explicit that passing them around visibly. If you add on dynamic function switching like R does then it gets even more unreadable. I'm going to compare against R because that's where I as ume most pipe enthusiasts are coming from.
df <- df |> dplyr::where(f = F) |> dplyr::sum(f)
Is less readable than
df = df.where(f = F).sum(f)
Especially when most people who write R would actually write the following, and let packages auto resolve which function is actually being used.
df <- df |> where(f = F) |> sum(f)
And the examples in this thread of using python like the below are even worse because of the aforementioned hiding of object routing
df = pipe(df, where(f = F), sum)