Skip to content

Commit

Permalink
Fixing #251 support for circular references in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Sep 18, 2023
1 parent cc26a46 commit 1e26885
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions box/box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def __new__(cls, *args, **kwargs):
# This is required for pickling to work correctly
obj.box_options = {"box_class": box.Box}
obj.box_options.update(kwargs)
obj.box_org_ref = 0
return obj

def __init__(self, iterable: Optional[Iterable] = None, box_class: Type[box.Box] = box.Box, **box_options):
self.box_options = box_options
self.box_options["box_class"] = box_class
self.box_org_ref = id(iterable) if iterable else 0
self.box_org_ref = iterable
if iterable:
for x in iterable:
self.append(x)
self.box_org_ref = None
if box_options.get("frozen_box"):

def frozen(*args, **kwargs):
Expand Down Expand Up @@ -101,7 +101,7 @@ def _convert(self, p_object):
elif isinstance(p_object, box.Box):
p_object._box_config.update(self.box_options)
if isinstance(p_object, list) and not self._is_intact_type(p_object):
p_object = self.__class__(p_object, **self.box_options)
p_object = self if p_object is self or p_object is self.box_org_ref else self.__class__(p_object, **self.box_options)
elif isinstance(p_object, BoxList):
p_object.box_options.update(self.box_options)
return p_object
Expand Down

0 comments on commit 1e26885

Please sign in to comment.