From 1e268857546c4b5602aae53e7856aa9e873b6af8 Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Mon, 18 Sep 2023 06:52:37 +0000 Subject: [PATCH] Fixing #251 support for circular references in lists --- box/box_list.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/box/box_list.py b/box/box_list.py index 048b014..12548a1 100644 --- a/box/box_list.py +++ b/box/box_list.py @@ -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): @@ -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