[Python-ideas] Method chaining notation
Steven D'Aprano
steve at pearwood.info
Mon Feb 24 16:16:23 CET 2014
On Mon, Feb 24, 2014 at 09:01:07AM -0600, Ron Adam wrote:
> You would probably see it used more often like this...
>
> def names(defaults, pos_names, pos_args, kwds):
> return {}.=update(defaults) \
> .=update(zip(pos_names, pos_args) \
> .=update(kwds)
>
>
> Normally .update returns None. The reason for that is so that it's clear
> you are mutating an object instead of creating a new one.
>
> By using .=, it can return self, but still maintain the clarity between
> mutation and non-mutation.
How does the update method know whether it is being called via . or via
.= ? I'm trying to understand how you think this is supposed to work,
and not having much success. Can you give a sketch of how this .= thingy
is supposed to operate?
> The other alternative is to use a function. But it would be difficult to
> get the same behaviour along with the same efficiency.
I don't see how you can compare the efficiency of code that can be
written now with code that doesn't exist yet. How do you know how
efficient your __iget_method__ suggestion will be?
--
Steven
More information about the Python-ideas
mailing list