MCPcopy Index your code
hub / github.com/RustPython/RustPython / __add__

Method __add__

crates/vm/src/builtins/tuple.rs:371–391  ·  view source on GitHub ↗
(
        zelf: PyRef<Self>,
        other: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

369)]
370impl PyTuple {
371 fn __add__(
372 zelf: PyRef<Self>,
373 other: PyObjectRef,
374 vm: &VirtualMachine,
375 ) -> PyArithmeticValue<PyRef<Self>> {
376 let added = other.downcast::<Self>().map(|other| {
377 if other.elements.is_empty() && zelf.class().is(vm.ctx.types.tuple_type) {
378 zelf
379 } else if zelf.elements.is_empty() && other.class().is(vm.ctx.types.tuple_type) {
380 other
381 } else {
382 let elements = zelf
383 .iter()
384 .chain(other.as_slice())
385 .cloned()
386 .collect::<Box<[_]>>();
387 Self { elements }.into_ref(&vm.ctx)
388 }
389 });
390 PyArithmeticValue::from_option(added.ok())
391 }
392
393 #[pymethod]
394 fn count(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {

Callers

nothing calls this directly

Calls 9

isMethod · 0.80
chainMethod · 0.80
okMethod · 0.80
mapMethod · 0.45
is_emptyMethod · 0.45
classMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected