itertools: defer dropwhile predicate validation - #8504
Conversation
Store the `dropwhile` predicate as a Python object and call it while advancing the iterator. This defers callable validation until the predicate is first needed, matching CPython for empty input while preserving exception propagation during iteration. Remove the now-passing `test_dropwhile` expected-failure marker. Assisted-by: Codex:gpt-5.6-sol
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesDropwhile predicate handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_itertools.py (TODO: 4) dependencies: dependent tests: (56 tests)
Legend:
|
Summary
Defer
itertools.dropwhile()predicate validation until iteration, matchingCPython's lazy behavior.
Details
dropwhilestored its predicate asArgCallable, which rejected anon-callable predicate during construction. CPython permits construction and
only calls (and therefore validates) the predicate when it consumes an item.
This matters for an empty iterable and for the timing of exceptions.
Store the predicate as
PyObjectRefand invoke it fromnext(). The changekeeps the existing first-false-item behavior and exception propagation while
aligning validation timing with CPython.
TestBasicOps.test_dropwhilenow passes with its existing CPython test body,so remove its
expectedFailuremarker.Testing
uv tool run prek run --all-filescargo fmt --checkcargo run --release Lib/test/test_itertools.pycargo run --release -- -m test test_itertoolscargo run -- extra_tests/snippets/stdlib_itertools.pycargo clippy -p rustpython-vm --all-targets -- -Dwarningscargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capigit diff --checkAI assistance: Codex:gpt-5.6-sol
Summary by CodeRabbit
dropwhilepredicate handling for more reliable iterator behavior.