On 15/11/2012 4:21pm, Terry Reedy wrote:
I was thinking that CPython could check the ref count of the input
keyword dict to determine whether it is newly created and can be
returned or is pre-existing and must be copied. But it seems not so.

 >>> def d(**x): return sys.getrefcount(x)

 >>> import sys
 >>> d(a = 3)
2
 >>> d(**{'a': 3})
2
 >>> b = {'a': 3}
 >>> d(**b)
2

I was expecting 3 for the last one.

Isn't it always newly created?

    >>> def f(**x): return x
    ...
    >>> b = {'a':3}
    >>> b is f(**b)
    False

--
Richard

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to