Skip to content

Commit 32899be

Browse files
committed
Fix lazy_list.pyx doctests to use picklable iterators
Instead of using try-except to catch unpicklable iterators like itertools.count (which can't be pickled in Python 3.14), changed the doctests to use list iterators which ARE picklable. This properly tests that the __reduce__ method works correctly while being compatible with Python 3.14's removal of pickle support for itertools objects.
1 parent 5580379 commit 32899be

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/sage/misc/lazy_list.pyx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,15 @@ cdef class lazy_list_generic():
534534
535535
EXAMPLES::
536536
537-
sage: from itertools import count
538537
sage: from sage.misc.lazy_list import lazy_list
539-
sage: m = lazy_list(count())
538+
sage: m = lazy_list(iter([0, 1, 4, 9, 16, 25, 36, 49, 64, 81]))
540539
sage: x = loads(dumps(m))
541540
sage: y = iter(x)
542541
sage: print("{} {} {}".format(next(y), next(y), next(y)))
543-
0 1 2
542+
0 1 4
544543
sage: m2 = m[3::2]
545544
sage: loads(dumps(m2))
546-
lazy list [3, 5, 7, ...]
545+
lazy list [9, 25, 49, ...]
547546
"""
548547
if self.master is None:
549548
raise NotImplementedError
@@ -916,8 +915,9 @@ cdef class lazy_list_from_iterator(lazy_list_generic):
916915
[0, 1, 2]
917916
sage: [next(x), next(y)]
918917
[3, 3]
919-
sage: loads(dumps(m))
920-
lazy list [0, 1, 2, ...]
918+
sage: m2 = lazy_list(iter([0, 1, 4, 9, 16]))
919+
sage: loads(dumps(m2))
920+
lazy list [0, 1, 4, ...]
921921
"""
922922

923923
def __init__(self, iterator, cache=None, stop=None):
@@ -986,10 +986,9 @@ cdef class lazy_list_from_iterator(lazy_list_generic):
986986
TESTS::
987987
988988
sage: from sage.misc.lazy_list import lazy_list_from_iterator
989-
sage: from itertools import count
990-
sage: loads(dumps(lazy_list_from_iterator(count())))
991-
lazy list [0, 1, 2, ...]
992-
sage: loads(dumps(lazy_list_from_iterator(count(), ['a'])))
989+
sage: loads(dumps(lazy_list_from_iterator(iter([0, 1, 4, 9, 16]))))
990+
lazy list [0, 1, 4, ...]
991+
sage: loads(dumps(lazy_list_from_iterator(iter([0, 1, 4, 9, 16]), ['a'])))
993992
lazy list ['a', 0, 1, ...]
994993
"""
995994
return lazy_list_from_iterator, (self.iterator, self.cache, self.stop)

0 commit comments

Comments
 (0)