[Python-ideas] Have dict().update() return its own reference.

Xavier Ho 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

    dict(x).update(y)

given x and y are both dict() instances.

Cheers,
Xav



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
>
> cheers
> lvh
>
>
>
> 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...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120420/43d93765/attachment.html>


More information about the Python-ideas mailing list