diff --git a/clvm/SExp.py b/clvm/SExp.py index 0f22a99f..48e90316 100644 --- a/clvm/SExp.py +++ b/clvm/SExp.py @@ -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() diff --git a/tests/as_python_test.py b/tests/as_python_test.py index 5c5c0d3d..092e7bad 100644 --- a/tests/as_python_test.py +++ b/tests/as_python_test.py @@ -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)