fix: handle itertools types in comparator with Python 3.9-3.14 support#1690
Merged
misrasaurabh1 merged 4 commits intomainfrom Feb 27, 2026
Merged
fix: handle itertools types in comparator with Python 3.9-3.14 support#1690misrasaurabh1 merged 4 commits intomainfrom
misrasaurabh1 merged 4 commits intomainfrom
Conversation
The comparator had no handler for itertools.count (an infinite iterator), causing it to fall through all type checks and return False even for equal objects. Use repr() comparison which reliably reflects internal state and avoids the __reduce__ deprecation coming in Python 3.14. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
itertools.repeat uses repr() comparison (same approach as count). itertools.cycle uses __reduce__() to extract internal state (saved items, remaining items, and first-pass flag) since repr() only shows a memory address. The __reduce__ approach is deprecated in 3.14 but is the only way to access cycle state without consuming elements. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
PR Review SummaryPrek ChecksAll checks pass (ruff check, ruff format). MypyNo new mypy errors introduced by this PR. Pre-existing errors in comparator.py (31) and test_comparator.py (456) remain unchanged. Code ReviewNo critical issues found. The implementation is well-structured:
Test Coverage
New code coverage: 30 new statements added, 24 covered (80%)
15 new test functions added covering all itertools types. Overall coverage improved slightly (+1%). Codeflash Optimization PRsNo open optimization PRs targeting main. All 29 open codeflash PRs target feature branches. Last updated: 2026-02-27 |
Add a catch-all handler for itertools iterators (chain, islice, product, permutations, combinations, starmap, accumulate, compress, dropwhile, takewhile, filterfalse, zip_longest, groupby, pairwise, batched, tee). Uses module check (type.__module__ == "itertools") so it automatically covers any itertools type without version-specific enumeration. groupby gets special handling to also materialize its group iterators. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Handle itertools.cycle on Python 3.14 where __reduce__ was removed by falling back to element-by-element sampling. Add version guards for pairwise (3.10+) and batched (3.12+) tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
itertoolstypes:count,repeat,cycle,chain,islice,product,permutations,combinations,accumulate,groupby,starmap,compress,dropwhile,takewhile,filterfalse,zip_longest,pairwise,batched, and morecountandrepeatuserepr()comparison;cycleuses__reduce__with a fallback for Python 3.14+ (where__reduce__was removed) that samples elements;groupbymaterializes groups; all others materialize to listspairwise(3.10+) andbatched(3.12+) testsTest plan
🤖 Generated with Claude Code