Skip to content

Commit

Permalink
Merge pull request #28 from Anaaa/fix-empty-sublist-case
Browse files Browse the repository at this point in the history
Fix replace_sublist when empty sublist is passed
  • Loading branch information
seberg authored Aug 27, 2024
2 parents 7a01758 + d7a3342 commit 95f8f74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/listwiz/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def replace_sublist(l, sublist, replacement):
"""
len_sublist = len(sublist)
if len_sublist == 0:
raise ValueError("The sublist cannot be empty. Please provide at least one element.")
result = l[:] # copy the input list

i = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def test_replace_sublist_overlap():


def test_replace_sublist_empty():
# This is a stub for testing the bug with empty sublists.
pass
with pytest.raises(ValueError, match="The sublist cannot be empty. Please provide at least one element."):
lwr.replace_sublist([1, 2, 3], [], [5, 6])

0 comments on commit 95f8f74

Please sign in to comment.