[Python-Dev] Inplace operations for PyLong objects
Manciu, Catalin Gabriel
catalin.gabriel.manciu at intel.com
Fri Sep 1 16:49:44 EDT 2017
> My question is -- how can the interpreter know if it can alter what is
> supposed to be an immutable in-place? If it's used only internally to a
> function, the it would be safe, but how to know that?
You can just check the reference count of your object, it's a member of the
PyObject structure which every CPython object contains: ob_refcnt. This will
indicate if your object is referenced by other Python variables or by Python
containers such as lists, tuples, dicts, sets etc.
More information about the Python-Dev