M
MRAB
The quote was:Am 19.08.2012 00:14 schrieb MRAB:
In simple terms, when you create an immutable object it can contain
only references to pre-existing objects, but in order to create a cycle
you need to make an object refer to another which is created later, so
it's not possible to create a cycle out of immutable objects.
Yes, but if I add a list in-between, I can create a refcycle:
a = []
b = (a,)
a.append(b)
So b is a tuple consisting of one list which in turn contains b.
It is not a direct cycle, but an indirect one.
Or would that be detected via the list?
'''
....The tuple type does not implement a tp_clear function, because it’s
possible to prove that no reference cycle can be composed entirely of
tuples.
'''
Note: "composed entirely of tuples".
Or, in general, composed entirely of immutables.
Lists are not immutable, therefore the proof does not apply.