Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #251 support for circular references in lists #259

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

CNSeniorious000
Copy link

@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.

@cdgriffith cdgriffith changed the base branch from master to develop September 19, 2023 00:16
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.

None yet

1 participant