You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
itertools.compress(x) calls x.__iter__() before reporting the missing selectors argument #9506
A call that leaves out a required argument converts the arguments it did pass first, so an exception from that conversion replaces the TypeError for the missing one. CPython counts the arguments before converting any.
itertools.compress(data=RaisingIter()) behaves the same.
Root cause
CompressNewArgs declares data as PyIter, and the FromArgs derive converts each field as soon as it takes it and reports a missing one only when it reaches that field (from_args.rs), so data.__iter__() runs first. FuncArgs::bind_for checks only the upper bound before T::from_args, while CPython's _PyArg_UnpackKeywords checks both bounds before itertools_compress_impl calls PyObject_GetIter.
Fix
In bind_for, before T::from_args, find the first required positional parameter in T::PARAMS that no positional or keyword argument fills and raise its error, next to the surplus check from #9242.
Environment
RustPython 713e14c (Python 3.15.0a), also reproduced on 0.4.0 and 0.6.1
AI disclosure: this report was drafted with Claude Code (claude-opus-5-5) and reviewed by me before submission. The divergence comes from a differential-testing run against CPython 3.12.13, and every source reference above was checked against the linked revisions.
Activity