GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reuse the shared optional argument binder for islice · RustPython/RustPython@c756f0d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/vm/src/stdlib
    • itertools.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/vm/src/stdlib/itertools.rs‎

Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/itertools.rs
+8-21Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -801,32 +801,19 @@ mod decl {
801801
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
802802
let args =
803803
crate::types::drop_kwargs_if_init_overridden(&cls, Self::class(&vm.ctx), args);
804-
let (iter, a1, a2, a3) = match args.args.len() {
805-
0 | 1 => {
806-
return Err(vm.new_arity_type_error(Self::NAME, 2..=4, args.args.len()));
807-
}
808-
2 => {
809-
let (iter, a1): (PyObjectRef, PyObjectRef) = args.bind_for(vm, Self::NAME)?;
810-
(iter, a1, None, None)
811-
}
812-
3 => {
813-
let (iter, a1, a2): (PyObjectRef, PyObjectRef, PyObjectRef) =
814-
args.bind_for(vm, Self::NAME)?;
815-
(iter, a1, Some(a2), None)
816-
}
817-
_ => {
818-
let (iter, a1, a2, a3): (PyObjectRef, PyObjectRef, PyObjectRef, PyObjectRef) =
819-
args.bind_for(vm, Self::NAME)?;
820-
(iter, a1, Some(a2), Some(a3))
821-
}
822-
};
804+
let (iter, a1, a2, a3): (
805+
PyObjectRef,
806+
PyObjectRef,
807+
OptionalArg<PyObjectRef>,
808+
OptionalArg<PyObjectRef>,
809+
) = args.bind_for(vm, Self::NAME)?;
823810

824811
// CPython clears index conversion errors and reports the appropriate
825812
// islice ValueError after converting arguments in this order.
826813
let to_ssize = |obj: &PyObject| isize::try_from_borrowed_object(vm, obj).unwrap_or(-1);
827814
let mut start = 0;
828815
let mut stop = -1;
829-
if let Some(a2) = &a2 {
816+
if let OptionalArg::Present(a2) = &a2 {
830817
if !vm.is_none(&a1) {
831818
start = to_ssize(&a1);
832819
}
@@ -853,7 +840,7 @@ mod decl {
853840
}
854841

855842
let mut step = 1;
856-
if let Some(a3) = &a3
843+
if let OptionalArg::Present(a3) = &a3
857844
&& !vm.is_none(a3)
858845
{
859846
step = to_ssize(a3);

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.