-
Notifications
You must be signed in to change notification settings - Fork 407
Add itertools adaptors: takewhile, dropwhile, filterfalse, starmap
#657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f99bfdb
116a6ff
e453638
821a76a
3072af3
90a131b
00bc69d
817392f
1e3d52f
e865ed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //! Calling a user-supplied predicate and taking its truthiness. | ||
| //! | ||
| //! Shared by `filter` and the `itertools` adaptors `takewhile`, `dropwhile` | ||
| //! and `filterfalse`, which differ only in what they do with the answer. | ||
|
|
||
| use crate::{args::ArgValues, bytecode::VM, defer_drop, exception_private::RunResult, types::PyTrait, value::Value}; | ||
|
|
||
| /// Applies `predicate` to `item` and returns its truthiness. | ||
| /// | ||
| /// `item` is only borrowed — the call gets its own reference, so the caller can | ||
| /// still yield the item afterwards. Goes through `evaluate_function`, which | ||
| /// runs a defined function's frame to completion, so a predicate that suspends | ||
| /// (an external function, an `os` call) is rejected rather than paused; `ctx` | ||
| /// names the caller in that error. | ||
| pub(crate) fn call_predicate(predicate: &Value, item: &Value, ctx: &'static str, vm: &mut VM<'_>) -> RunResult<bool> { | ||
| let arg = item.clone_with_heap(vm.heap); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Predicate invocation now has two semantically identical ownership and evaluation paths, so future fixes to callable errors or heap cleanup can diverge between Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — |
||
| let result = vm.evaluate_function(ctx, predicate, ArgValues::One(arg))?; | ||
| // Guarded because `py_bool` can raise through a user `__bool__`. | ||
| defer_drop!(result, vm); | ||
| result.py_bool(vm) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff is here because cubic asked for it (see the thread on
predicate.rs).builtin_filteris pre-existing and otherwise untouched by this branch — the change routes it throughcall_predicate, the helper this PR adds fortakewhile/dropwhile/filterfalse, so the two predicate-call paths cannot drift apart. Behaviour-neutral.