(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine)
| 219 | type Args = Vec<PyObjectRef>; |
| 220 | |
| 221 | fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { |
| 222 | let iterable: OptionalArg<PyObjectRef> = args.bind(vm)?; |
| 223 | |
| 224 | // Optimizations for exact tuple type |
| 225 | if cls.is(vm.ctx.types.tuple_type) { |
| 226 | // Return exact tuple as-is |
| 227 | if let OptionalArg::Present(ref input) = iterable |
| 228 | && let Ok(tuple) = input.clone().downcast_exact::<PyTuple>(vm) |
| 229 | { |
| 230 | return Ok(tuple.into_pyref().into()); |
| 231 | } |
| 232 | |
| 233 | // Return empty tuple singleton |
| 234 | if iterable.is_missing() { |
| 235 | return Ok(vm.ctx.empty_tuple.clone().into()); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | let elements = if let OptionalArg::Present(iterable) = iterable { |
| 240 | iterable.try_to_value(vm)? |
| 241 | } else { |
| 242 | vec![] |
| 243 | }; |
| 244 | |
| 245 | // Return empty tuple singleton for exact tuple types (when iterable was empty) |
| 246 | if elements.is_empty() && cls.is(vm.ctx.types.tuple_type) { |
| 247 | return Ok(vm.ctx.empty_tuple.clone().into()); |
| 248 | } |
| 249 | |
| 250 | let payload = Self::py_new(&cls, elements, vm)?; |
| 251 | payload.into_ref_with_type(vm, cls).map(Into::into) |
| 252 | } |
| 253 | |
| 254 | fn py_new(_cls: &Py<PyType>, elements: Self::Args, _vm: &VirtualMachine) -> PyResult<Self> { |
| 255 | Ok(Self { |
nothing calls this directly
no test coverage detected