Skip to content

Fixing #251 support for circular references in lists#259

Merged
cdgriffith merged 2 commits intocdgriffith:developfrom
CNSeniorious000:master
Jun 12, 2024
Merged

Fixing #251 support for circular references in lists#259
cdgriffith merged 2 commits intocdgriffith:developfrom
CNSeniorious000:master

Conversation

@CNSeniorious000
Copy link
Copy Markdown
Contributor

@CNSeniorious000 CNSeniorious000 commented Sep 18, 2023

I read #251 and think that using is operator to identify objects may fix the problem id brings.

For now, you can:

  1. 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
  1. 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:

  1. For performance, it is a waste to always hold a reference for the iterable passing to __init__.
  2. After initialization, a is not the same as b anymore, I think users appending b to a is not intended to append a to a.

@CNSeniorious000 CNSeniorious000 force-pushed the master branch 2 times, most recently from c78844d to 1e26885 Compare September 18, 2023 07:16
@cdgriffith cdgriffith changed the base branch from master to develop September 19, 2023 00:16
@cdgriffith
Copy link
Copy Markdown
Owner

I have no idea how this fell off my radar, I apologize!

Thank you so much for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants