Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clvm/SExp.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def null(class_) -> SExp:

def as_iter(self: _T_SExp) -> typing.Iterator[_T_SExp]:
v = self
while not v.nullp():
while v.pair is not None:
yield v.first()
v = v.rest()

Expand Down
11 changes: 6 additions & 5 deletions tests/as_python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ def test_as_iter(self) -> None:
val = list(SExp.to((1, b"")).as_iter())
self.assertEqual(val, [1])

# these fail because the lists are not null-terminated
self.assertRaises(EvalError, lambda: list(SExp.to(1).as_iter()))
self.assertRaises(
EvalError, lambda: list(SExp.to((1, (2, (3, (4, 5))))).as_iter())
)
# we accept lists that are not null-terminated
val = list(SExp.to(1).as_iter())
self.assertEqual(val, [])

val = list(SExp.to((1, (2, (3, (4, 5))))).as_iter())
self.assertEqual(val, [1, 2, 3, 4])

def test_eq(self) -> None:
val = SExp.to(1)
Expand Down