(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine)
| 590 | type Args = PyCodeNewArgs; |
| 591 | |
| 592 | fn py_new(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> { |
| 593 | // Convert names tuple to vector of interned strings |
| 594 | let names: Box<[&'static PyStrInterned]> = args |
| 595 | .names |
| 596 | .iter() |
| 597 | .map(|obj| { |
| 598 | let s = obj |
| 599 | .downcast_ref::<super::pystr::PyStr>() |
| 600 | .ok_or_else(|| vm.new_type_error("names must be tuple of strings"))?; |
| 601 | Ok(vm.ctx.intern_str(s.as_wtf8())) |
| 602 | }) |
| 603 | .collect::<PyResult<Vec<_>>>()? |
| 604 | .into_boxed_slice(); |
| 605 | |
| 606 | let varnames: Box<[&'static PyStrInterned]> = args |
| 607 | .varnames |
| 608 | .iter() |
| 609 | .map(|obj| { |
| 610 | let s = obj |
| 611 | .downcast_ref::<super::pystr::PyStr>() |
| 612 | .ok_or_else(|| vm.new_type_error("varnames must be tuple of strings"))?; |
| 613 | Ok(vm.ctx.intern_str(s.as_wtf8())) |
| 614 | }) |
| 615 | .collect::<PyResult<Vec<_>>>()? |
| 616 | .into_boxed_slice(); |
| 617 | |
| 618 | let cellvars: Box<[&'static PyStrInterned]> = args |
| 619 | .cellvars |
| 620 | .iter() |
| 621 | .map(|obj| { |
| 622 | let s = obj |
| 623 | .downcast_ref::<super::pystr::PyStr>() |
| 624 | .ok_or_else(|| vm.new_type_error("cellvars must be tuple of strings"))?; |
| 625 | Ok(vm.ctx.intern_str(s.as_wtf8())) |
| 626 | }) |
| 627 | .collect::<PyResult<Vec<_>>>()? |
| 628 | .into_boxed_slice(); |
| 629 | |
| 630 | let freevars: Box<[&'static PyStrInterned]> = args |
| 631 | .freevars |
| 632 | .iter() |
| 633 | .map(|obj| { |
| 634 | let s = obj |
| 635 | .downcast_ref::<super::pystr::PyStr>() |
| 636 | .ok_or_else(|| vm.new_type_error("freevars must be tuple of strings"))?; |
| 637 | Ok(vm.ctx.intern_str(s.as_wtf8())) |
| 638 | }) |
| 639 | .collect::<PyResult<Vec<_>>>()? |
| 640 | .into_boxed_slice(); |
| 641 | |
| 642 | // Check nlocals matches varnames length |
| 643 | if args.nlocals as usize != varnames.len() { |
| 644 | return Err(vm.new_value_error(format!( |
| 645 | "nlocals ({}) != len(varnames) ({})", |
| 646 | args.nlocals, |
| 647 | varnames.len() |
| 648 | ))); |
| 649 | } |
nothing calls this directly
no test coverage detected