[Python-ideas] Have dict().update() return its own reference.
contact at xavierho.com
Fri Apr 20 14:37:45 CEST 2012
Thanks, that's fair, for consistency.
One use case for my question was a stackoverflow question regarding merging
two dict's. If update() returned its own reference, and if we explicitly
wanted a copy (instead of an in-place modification), we could have used
given x and y are both dict() instances.
On 20 April 2012 22:35, Laurens Van Houtven <_ at lvh.cc> wrote:
> As a general rule, methods/functions in Python either *mutate* or
> *return*. (Obviously, mutating methods also return, they just return None)
> For example: random.shuffle shuffles in place so doesn't return anything
> list.sort sorts in place so doesn't return anything
> sorted creates a new sorted thing, so returns that sorted thing
> On 20 Apr 2012, at 14:32, Xavier Ho wrote:
> > Hello,
> > What's the rationale behind the fact that `dict().update()` return
> nothing? If it returned the dictionary reference, at least we could chain
> methods, or assign it to another variable, or pass it into a function, etc..
> > What's the design decision made behind this?
> > Cheers,
> > Xav
> > _______________________________________________
> > Python-ideas mailing list
> > Python-ideas at python.org
> > http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas