Add a new token to force the methods to returns the previous object

I view it a bit differently. There is (at least some) desire in the ecosystem to support method chaining but so far the common practice is usually to not return self if a call has side effects. Brett made a great comment about that in another thread: Support method chaining in pathlib - #2 by brettcannon

Adding a dedicated operator would allow the API design to continue as is while simultaneously giving user the option to use chaining explicitly. This could ultimately lead to better APIs as devs might not feel pressured anymore to support chaining even if it doesn’t make sense for their project / API.

Not sure I’m convinced yet .& is the right syntax. Why not use .. for it?

>>> hex = (
>>>     sha1(b'foo')
>>>         ..update(b'bar')
>>>         ..hexdigest()
>>> )

The formatting is probably something that should be considered here as well. Using newlines like above does make sense IMO but can get verbose fairly quickly.

Another issue to consider might be async function calls. Not sure how to handle these best.

2 Likes