fix(list): handle cyclic reference when stringifying

This commit is contained in:
2026-02-09 01:55:59 +01:00
parent fb7723406c
commit fe747656d8

View File

@@ -14,6 +14,7 @@ if TYPE_CHECKING:
class PebbleList(metaclass=BuiltinType):
def __init__(self, items: Optional[list[Any]] = None):
self.items: list[Any] = items or []
self._stringify_visited: bool = False
def get(self, index: Any, bracket: Token):
idx: int = Cast.as_int(bracket, index)
@@ -24,7 +25,12 @@ class PebbleList(metaclass=BuiltinType):
self.items[idx] = value
def __str__(self):
return "[" + ", ".join(map(lambda item: StringFormatter.stringify(item, True), self.items)) + "]"
if self._stringify_visited:
return "[...]"
self._stringify_visited = True
res: str = "[" + ", ".join(map(lambda item: StringFormatter.stringify(item, True), self.items)) + "]"
self._stringify_visited = False
return res
# Exposed methods
@exposed(nargs=1)