Skip to content

Commit 4aa77cd

Browse files
CodingFeng101mahmoud
authored andcommitted
Fix split maxsplit zero handling
1 parent 3970a80 commit 4aa77cd

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

boltons/iterutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def split_iter(src, sep=None, maxsplit=None):
158158
if maxsplit is not None:
159159
maxsplit = int(maxsplit)
160160
if maxsplit == 0:
161-
yield [src]
161+
yield list(src)
162162
return
163163

164164
if callable(sep):

tests/test_iterutils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from boltons.dictutils import OMD
66
from boltons.iterutils import (first,
7+
split,
78
pairwise,
89
pairwise_iter,
910
windowed,
@@ -24,6 +25,14 @@
2425
is_meaning_of_life = lambda x: x == 42
2526

2627

28+
class TestSplit:
29+
def test_maxsplit_zero_returns_unsplit_values(self):
30+
values = [1, None, 2]
31+
32+
assert split(values, maxsplit=0) == [values]
33+
assert split(iter(values), maxsplit=0) == [values]
34+
35+
2736
class TestFirst:
2837
def test_empty_iterables(self):
2938
"""
@@ -634,4 +643,3 @@ def test_partition_multiple():
634643
assert positive == [2, 3]
635644
assert negative == [-1, -2]
636645
assert zero == [0]
637-

0 commit comments

Comments
 (0)