Skip to content

fix: handle itertools types in comparator with Python 3.9-3.14 support#1690

Merged
misrasaurabh1 merged 4 commits intomainfrom
fix/comparator-itertools-count
Feb 27, 2026
Merged

fix: handle itertools types in comparator with Python 3.9-3.14 support#1690
misrasaurabh1 merged 4 commits intomainfrom
fix/comparator-itertools-count

Conversation

@aseembits93
Copy link
Copy Markdown
Contributor

@aseembits93 aseembits93 commented Feb 27, 2026

Summary

  • Added comparator handlers for all itertools types: count, repeat, cycle, chain, islice, product, permutations, combinations, accumulate, groupby, starmap, compress, dropwhile, takewhile, filterfalse, zip_longest, pairwise, batched, and more
  • count and repeat use repr() comparison; cycle uses __reduce__ with a fallback for Python 3.14+ (where __reduce__ was removed) that samples elements; groupby materializes groups; all others materialize to lists
  • Added version guards for pairwise (3.10+) and batched (3.12+) tests
  • Comprehensive test coverage across Python 3.10–3.14

Test plan

  • All comparator tests pass on Python 3.10 (157 passed, 46 skipped)
  • All comparator tests pass on Python 3.11 (159 passed, 44 skipped)
  • All comparator tests pass on Python 3.12 (160 passed, 43 skipped)
  • All comparator tests pass on Python 3.13 (160 passed, 43 skipped)
  • All comparator tests pass on Python 3.14 (160 passed, 43 skipped)

🤖 Generated with Claude Code

aseembits93 and others added 2 commits February 27, 2026 23:01
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>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 27, 2026

PR Review Summary

Prek Checks

All checks pass (ruff check, ruff format).

Mypy

No new mypy errors introduced by this PR. Pre-existing errors in comparator.py (31) and test_comparator.py (456) remain unchanged.

Code Review

No critical issues found. The implementation is well-structured:

  • Infinite iterators (count, repeat, cycle) are correctly handled before the generic materializer, preventing hangs
  • Python 3.10-3.14 compatibility is properly handled - cycle uses reduce with a TypeError fallback for 3.14+ where reduce was removed
  • groupby is correctly special-cased to materialize lazy group iterators
  • Generic itertools handler uses type(orig).module == "itertools" as a catch-all for finite itertools types
  • Tests are comprehensive: equality, inequality, partial consumption, container nesting, and version-gated tests (pairwise for 3.10+, batched for 3.12+)

Test Coverage

File Main PR Change
codeflash/verification/comparator.py 59% (401 stmts) 60% (431 stmts) +1%

New code coverage: 30 new statements added, 24 covered (80%)

  • Covered: count, repeat, cycle (reduce path), groupby, generic itertools handler
  • Not covered (expected): Line 558 (started != started edge case), Lines 562-568 (Python 3.14+ fallback path)

15 new test functions added covering all itertools types. Overall coverage improved slightly (+1%).

Codeflash Optimization PRs

No open optimization PRs targeting main. All 29 open codeflash PRs target feature branches.


Last updated: 2026-02-27

aseembits93 and others added 2 commits February 27, 2026 23:14
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>
@aseembits93 aseembits93 changed the title fix: handle itertools.count in comparator fix: handle itertools types in comparator with Python 3.9-3.14 support Feb 27, 2026
@misrasaurabh1 misrasaurabh1 merged commit 86202d4 into main Feb 27, 2026
25 of 28 checks passed
@misrasaurabh1 misrasaurabh1 deleted the fix/comparator-itertools-count branch February 27, 2026 23:22
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