Skip to content

Fix interpose([]) raising StopIteration - #635

Merged
eriknw merged 1 commit into
pytoolz:masterfrom
Pitchfork-and-Torch:fix/interpose-empty-seq
Sep 18, 2026
Merged

eriknw merged 1 commit into
pytoolz:masterfrom
Pitchfork-and-Torch:fix/interpose-empty-seq

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown
Contributor

Summary

  • interpose(el, []) called next() on an empty concat/zip pipeline and raised StopIteration.
  • Catch that case and return an empty iterator; nonempty behavior unchanged.
  • Adds a regression test.

Test plan

  • pytest toolz/tests/test_itertoolz.py -k interpose
  • Manual: list(interpose('a', [])) == [] and list(interpose('a', [1,2,3])) == [1,'a',2,'a',3]

Calling next() on the zip/concat pipeline assumes at least one element.
Return an empty iterator for empty sequences instead.
@eriknw
eriknw merged commit d2eba03 into pytoolz:master Sep 18, 2026
16 checks passed
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a1e25cb) to head (22b34ec).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #635   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines         1226      1229    +3     
=========================================
+ Hits          1226      1229    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eriknw

eriknw commented Sep 18, 2026

Copy link
Copy Markdown
Member

Good catch! cytoolz already matches this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants