> 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?

> -CHB

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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to