Box
Box copied to clipboard
Fixing #251 support for circular references in lists
I read #251 and think that using is
operator to identify objects may fix the problem id
brings.
For now, you can:
- initialize a
BoxList
with a list with circular references
>>> from box import BoxList
>>> a = []
>>> a.append(a)
>>> a
[[...]]
>>> b = BoxList(a)
>>> b
BoxList([[...]])
>>> b[0][0][0][0] is b
True
- reference oneself after creation
>>> a = BoxList()
>>> a
BoxList([])
>>> a.append(a)
>>> a
BoxList([[...]])
>>> a[0][0][0][0] is a
True
Note this:
>>> a = []
>>> b = BoxList(a)
>>> b.append(a)
>>> b
BoxList([[]])
>>> b[0] is a
False
This is because:
- For performance, it is a waste to always hold a reference for the
iterable
passing to__init__
. - After initialization,
a
is not the same asb
anymore, I think users appendingb
toa
is not intended to appenda
toa
.