[C++-sig] dict surprise

David Abrahams david.abrahams at rcn.com
Sat Jul 20 13:39:20 CEST 2002


From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>


> I was surprised to find that
>
> dict(w_obj.attr("__dict__")).update(some_tuple[0]);
>
> only updates the temporary created by dict(), but not the original
__dict__.
> Eventually I got the desired behavior by using
>
> w_obj.attr("__dict__").attr("update")(object(some_tuple[0]));
>
> I convinced myself that the first statement works just the way Python
works, so
> fine. However, this is a bit of a trap for the novice and a specific
warning in
> the documentation ("don't use dict(obj1).update(obj2)") would probably be
very
> helpful.

We'd have to warn about list, too, and probably a whole host of others. Is
it worth it?
This seems like a corner case to me.

> Ralf
>
> P.S.: I love the new extract<T> .

I'm glad!
I hope you're using it with T = U& to avoid copies when appropriate...

-Dave







More information about the Cplusplus-sig mailing list