Cpython: when to incref before insertdict

Marco Sulla Marco.Sulla.Python at gmail.com
Sat Mar 5 09:20:51 EST 2022


I noticed that some functions inside dictobject.c that call insertdict
or PyDict_SetItem do an incref of key and value before the call, and a
decref after it. An example is dict_merge. Other functions, such as
_PyDict_FromKeys, don't do an incref before.

When an incref of key and value is needed before insertdict and when
is not? And why is an incref needed?


More information about the Python-list mailing list